How to deal with data of class uneval error from ggplot2?
when you add a new data set to a geom you need to use the data=
argument. Or put the arguments in the proper order mapping=..., data=...
. Take a look at the arguments for ?geom_line
.
Thus:
p + geom_line(data=df.last, aes(HrEnd, MWh, group=factor(Date)), color="red")
Or:
p + geom_line(aes(HrEnd, MWh, group=factor(Date)), df.last, color="red")
Error: ggplot2 doesn't know how to deal with data of class uneval
Sorry to say it, but i can't believe that you have searched around — it is a quite rudimentary mistake you are making. I would suggest that you check out this brilliant resource for learning ggplot and friends: http://r4ds.had.co.nz/. As for your question, the problem is that you are only calling geom_bar()
, instead your code should look like this:
ggplot(Primary2016, aes(SandersPercent, Type)) +
geom_bar()
error : ggplot2 doesn't know how to deal with data of class uneval
Your problem is that you didn't specify what argument data
is in stat_density
. If you look at ?stat_density
you'll see the first implied argument is actually mapping=
. You need to change pdf.plot
to:
pdf.plot<-function(data,x,xl,yl,title,save){
ggplot() +
stat_density(data = data, kernel = "biweight",aes_string(x=x, colour='id'),
position="identity",geom="line")+
coord_cartesian(xlim = c(0, 200))+
xlab(xl)+
ylab(yl)+
ggtitle(title)+
ggsave(save)
}
Why do I keep getting Error: ggplot2 doesn't know how to deal with data of class uneval?
Turns out that when I haven't set up a ggplot function in a while I always, always, always...forget that ggplot doesn't use the %>%
pipe characters to chain functions!
Instead of %>%
I should be putting +
between my ggplot functions.
To summarize:
BAD
cleaned.data %>%
ggplot(aes(x = date)) %>%
geom_line(aes(y = analysis.value, col = columns))
GOOD
cleaned.data %>%
ggplot(aes(x = date)) +
geom_line(aes(y = analysis.value, col = columns))
I always wind up searching SO frantically for about 20 minutes only to eventually realize that I've made the same mistake again.
Related Topics
Exactly Storing Large Integers
How to Add Multiple Captions in Ggplot2 Outside of the Main Graph Area
Take Sum of a Variable If Combination of Values in Two Other Columns Are Unique
R Semicolon Delimited a Column into Rows
How to Suppress the Vertical Gridlines in a Ggplot2 Plot
How Does One Stop Using Rowwise in Dplyr
How to Save() with a Particular Variable Name
Add a New Column to a Dataframe Using Matching Values of Another Dataframe
Ggplot2: Color Individual Words in Title to Match Colors of Groups
Overlay Two Ggplot2 Stat_Density2D Plots with Alpha Channels
How Can a Data Ellipse Be Superimposed on a Ggplot2 Scatterplot
Add Margin Row Totals in Dplyr Chain
Importing CSV File into R - Numeric Values Read as Characters