dplyr + ggplot2: Plotting not working via piping

I want to plot a subset of my dataframe. I am working with dplyr and ggplot2. My code only works with version 1, not version 2 via piping. What's the difference?

Version 1 (plotting is working):

data <- dataset %>% filter(type=="type1")
ggplot(data, aes(x=year, y=variable)) + geom_line()

Version 2 with piping (plotting is not working):

data %>% filter(type=="type1") %>% ggplot(data, aes(x=year, y=variable)) + geom_line()

Error:

Error in ggplot.data.frame(., data, aes(x = year,  : 
Mapping should be created with aes or aes_string

Thanks for your help!

Answers


Solution for version 2: a dot . instead of data:

data %>% filter(type=="type1") %>% ggplot(., aes(x=year, y=variable)) + geom_line()

Need Your Help

Call method every time a controller method is ending

c# asp.net-mvc asp.net-mvc-4 razor

Basically I got a static class called NotificationManager. Every time a controller method is called I want to store the modelerrors in the notificationmanager.

get list in plain text using regex

php regex text-processing plaintext

I want to get all the list items in a plain text (.txt file) using regex. For example in:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.