GGPLOT问题;代码将线路绘制为一些非常奇怪的条。为什么这是?
在绘制来自数据框架的一些数据时,我有一些问题。它似乎将多个系列视为同一行。有人知道为什么这是吗?
dataframe代码创建df:
df <- read.table(text="Date Item Purchased
01/01/08 Fruit 48
01/01/08 Confectionary 42
01/01/08 Appliance 11
01/06/08 Confectionary 16
01/06/08 Fruit 19
01/06/08 Appliance 50", header=TRUE)
我要绘制数据
test_df <- ggplot(df)+geom_line(aes(x=Date, y=Purchased, color=Item, group = 1),size=8)+
theme(title=element_text(size=10),panel.background = element_rect(fill='white'),legend.position='top')+geom_hline(yintercept = 0,color="white")
test_df
我想绘制一些时间这些数据系列; “水果”的一条线,一个用于“糖果”的行,另一个用于“设备”。有人知道为什么这样做吗?
I'm having a bit of a problem when it comes to plotting some data from a dataframe. It seems to treat multiple series as being the same line. Does anyone know why this is?
Dataframe code to create df:
df <- read.table(text="Date Item Purchased
01/01/08 Fruit 48
01/01/08 Confectionary 42
01/01/08 Appliance 11
01/06/08 Confectionary 16
01/06/08 Fruit 19
01/06/08 Appliance 50", header=TRUE)
My code to plot data:
test_df <- ggplot(df)+geom_line(aes(x=Date, y=Purchased, color=Item, group = 1),size=8)+
theme(title=element_text(size=10),panel.background = element_rect(fill='white'),legend.position='top')+geom_hline(yintercept = 0,color="white")
test_df
I'd like to plot some time series of this data; one line for 'Fruit', one for 'Confectionary' and one for 'Appliance'. Does anyone know why it's doing this?
*EDIT: Adding x=lubridate::mdy(Date) produces thee following result:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢MRFlick,问题包括该组= 1
With thanks to MrFlick, the issue was including the group=1