ggplot2에서 "데이터 클래스 비정상"오류를 처리하는 방법은 무엇입니까?
기존 ggplot에 새 줄을 오버레이하려고 시도하는 동안 다음 오류가 발생합니다.
Error: ggplot2 doesn't know how to deal with data of class uneval
내 코드의 첫 번째 부분이 잘 작동합니다. 아래는 미국 중서부 전력 시장의 "최근"시간별 풍력 발전 데이터 이미지입니다.
이제 지난 이틀 동안의 관찰을 Red로 오버레이하고 싶습니다. 쉽지만 오류가 발생하는 이유를 알 수 없습니다.
어떤 도움이라도 대단히 감사하겠습니다.
다음은 재현 가능한 예입니다.
# 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
geom에 새 데이터 세트를 추가 할 때 data=
인수 를 사용해야합니다 . 또는 적절한 순서로 인수를 넣으십시오 mapping=..., data=...
. 에 대한 인수를 살펴보십시오 ?geom_line
.
그러므로:
p + geom_line(data=df.last, aes(HrEnd, MWh, group=factor(Date)), color="red")
또는:
p + geom_line(aes(HrEnd, MWh, group=factor(Date)), df.last, color="red")
또 다른 원인은 실수 로 외부 대신 data=...
내부를 넣는 aes(...)
것입니다.
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 your plot command with qplot()
, which doesn't use an explicit aes()
, then edit/copy-and-paste it into a ggplot()
qplot(data=..., x=...,y=..., ...)
ggplot(data=..., aes(x=...,y=...,...))
It's a pity ggplot's error message isn't Missing 'data' argument! instead of this cryptic nonsense, because that's what this message often means.
This could also occur if you refer to a variable in the data.frame that doesn't exist. For example, recently I forgot to tell ddply to summarize by one of my variables that I used in geom_line to specify line color. Then, ggplot didn't know where to find the variable I hadn't created in the summary table, and I got this error.
'Programing' 카테고리의 다른 글
iOS 6 : 일부보기를 세로로 제한하고 다른보기는 회전하도록 허용하려면 어떻게합니까? (0) | 2020.08.20 |
---|---|
Python에서 2 차원 배열 회전 (0) | 2020.08.20 |
브라우저에서 채널을 열기위한 Slack URL (0) | 2020.08.20 |
java.util.Optional이 Serializable이 아닌 이유, 이러한 필드로 객체를 직렬화하는 방법 (0) | 2020.08.20 |
문제가 NP 완전하다는 것을 증명하는 방법은 무엇입니까? (0) | 2020.08.20 |