How to deal with the "data class uneval" error from ggplot2?

When I try to overlay a new line on an existing ggplot, I get the following error:

Error: ggplot2 doesn't know how to deal with data of class uneval 

The first part of my code is working fine. Below is an image of the β€œrecent” hourly data on wind generation from the electricity market in the Midwestern United States.

Recent Hourly Wind Data

Now I want to overlay the last two days of observation in Red. This should be easy, but I can’t understand why I am getting an error.

Any help would be greatly appreciated.

The following is a reproducible example:

 # Read in Wind data fname <- "https://www.midwestiso.org/Library/Repository/Market%20Reports/20130510_hwd_HIST.csv" df <- read.csv(fname, header=TRUE, sep="," , skip=7) df <- df[1:(length(df$MKTHOUR)-5),] # format variables df$MWh <- as.numeric(df$MWh) df$Datetime <- strptime(df$MKTHOUR, "%m/%d/%y %I:%M %p") # Create some variables df$Date <- as.Date(df$Datetime) df$HrEnd <- df$Datetime$hour+1 # Subset recent and last data last.obs <- range(df$Date)[2] df.recent <- subset(df, Date %in% seq(last.obs-30, last.obs-2, by=1)) df.last <- subset(df, Date %in% seq(last.obs-2, last.obs, by=1)) # plot recent in Grey p <- ggplot(df.recent, aes(HrEnd, MWh, group=factor(Date))) + geom_line(color="grey") + scale_y_continuous(labels = comma) + scale_x_continuous(breaks = seq(1,24,1)) + labs(y="MWh") + labs(x="Hour Ending") + labs(title="Hourly Wind Generation") p # plot last two days in Red p <- p + geom_line(df.last, aes(HrEnd, MWh, group=factor(Date)), color="red") p 
+70
r ggplot2
May 10 '13 at 16:31
source share
3 answers

when you add a new dataset to the geometry, you need to use the data= argument. Or put the arguments in the correct order mapping=..., data=... Take a look at the arguments for ?geom_line .

In this way:

 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") 
+120
May 10 '13 at 16:33
source share
β€” -

Another reason is the random placement of data=... inside aes(...) instead of the outer one:

 RIGHT: ggplot(data=df[df$var7=='9-06',], aes(x=lifetime,y=rep_rate,group=mdcp,color=mdcp) ...) WRONG: ggplot(aes(data=df[df$var7=='9-06',],x=lifetime,y=rep_rate,group=mdcp,color=mdcp) ...) 

In particular, this can happen when you prototype the plot command with qplot() , which does not use explicit aes() , and then edits / copies and ggplot() it into ggplot()

 qplot(data=..., x=...,y=..., ...) ggplot(data=..., aes(x=...,y=...,...)) 

It is a pity that the ggplot error message did not miss the "data" argument! instead of this cryptic stupidity, because it often means this message.

+9
Mar 30 '14 at 12:20
source share

This can also happen if you reference a variable in data.frame that does not exist. For example, I recently forgot to say ddply to summarize one of my variables, which I used in geom_line to indicate the color of the line. Then ggplot did not know where to find the variable that I did not create in the pivot table, and I got this error.

+3
Aug 05 '15 at 13:47
source share



All Articles