줄거리를 몇 줄 추가하고 옆에 텍스트가 있습니다.ggplot에서 여러 줄 옆에 텍스트를 추가하는 방법은 무엇입니까?
Price <- seq(1, 20, by=1)
MW <- seq(1, 200, by=10)
fuel <- rep(c("Coal", "Gas", "Hydro", "Other"), each=5)
Day <- rep(1, each=20)
df1 <- data.frame(Price, MW,fuel, Day)
Price<-seq(0, 19, by=1)
MW <- seq(1, 100, by=5)
Day <- rep(2, each=20)
df2 <- data.frame(Price, MW, fuel, Day)
df <- rbind(df1, df2)
df <- df[with(df, order(Day, Price, fuel)), ]
library(ggplot2)
Lines<-data.frame(Level=c("mean", "Median"), vals=c(50, 100), lables=c("mean: 50", "Median: 100"))
Lines$valy<-10
ggplot(df, aes(x=MW, y=Price, group=Day))+
geom_point(aes(colour=fuel, shape=as.factor(Day)))+
geom_line(aes(colour=fuel))+
geom_vline(data=Lines, mapping=aes(xintercept=vals), color="blue") +
geom_text(data = Lines,
aes(x=vals, y=valy, label=lables, colour="blue"),
hjust = 1)
내가 오류를 받고 있어요 왜 어떤 생각 :
Error: Aesthetics must either be length one, or the same length as the dataProblems:vals, valy, lables
가 나는 또한 오류 설정 내 주요 데이터에서이 작업을 수행하지만 얻기 위해 노력했다 :
object 'indexMO' not found
내 코드가 있습니다 :
ggplot(tSub, aes(x=cumsum, y=Price, group=indexMO))+
geom_line(aes(colour=FuelType))+
geom_point(aes(colour=FuelType))+
scale_y_continuous("Price",breaks= seq(0,1000,by=50),labels = comma_format())+
scale_x_continuous("Dispatchable Energy (MW)",breaks= seq(0,12000,by=500),labels = comma_format())+
ggtitle(expression(atop("Minimum, Median, and Maximum Merit Orders for 2013", atop(italic("Based on Total Dispatchable MW"), "")))) +
theme(axis.text.x = element_text(angle=-45, hjust=0, vjust=1),
#plot.margin = unit(c(1.5, 1, 1, 1), "cm"),
plot.title = element_text(size = 16, face = "bold", colour = "black", vjust = -1))+
theme(axis.text.x = element_text(colour = 'black', face = 'bold'))+
theme(axis.text.y = element_text(colour = 'black', face = 'bold'))+
geom_vline(data=Dispatched, mapping=aes(xintercept=vals), color="blue") +
geom_text(data = Dispatched,
aes(x=vals, y=yval, label=LineLables, colour="blue"),
hjust = 1)
하지만이 d oes는 위의 코드와 거의 같습니다.
'dput (tSub)'할 수 있습니까? – hrbrmstr