How to Deal with "Data of Class Uneval" Error from Ggplot2

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



Leave a reply



Submit