我正在尝试绘制一个线形图以及数据集的点。不幸的是,我无法在图中绘制线条,但是,点是绘制出来的吗?我得到的错误是geom_path:每个组只包含一个观察值。您是否需要调整群组美学?有人能帮我吗?
我已经确保所有变量要么是数字,要么是字符,而不是因子。我还试图将他们标记为组,但这不起作用。
df<- c('a','b','c','d','e')
df1<-1:5
df2<-11:15
df3<-21:25
df4<-cbind(df,df1,df2,df3)
colnames(df4)<-c("Names", "P1","P2","P3")
df4<-as.data.frame(df4)
dfplot <- gather(df4,key="Period", value="Price",-Names,P1,P2,P3 )
dfplot<-dfplot[order(dfplot$Names),]
vars<-c("Price")
vars1<-c("Names","Period")
dfplot[vars] <- sapply(dfplot[vars], as.numeric)
dfplot[vars1]<-sapply(dfplot[vars1], as.character)
ggplot(dfplot, aes(x = Period, y = Price, color = Names),group=5 ) + geom_line()+geom_point()发布于 2019-05-17 21:57:07
当您的数据被分组时,您需要告诉geom_line()数据分组在哪个字段上:
ggplot(dfplot, aes(x = Period, y = Price, color = Names),group=5 ) + geom_line(aes(group=Names))+geom_point()Some more information
https://stackoverflow.com/questions/56187874
复制相似问题