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:
CodePudding user response:
With thanks to MrFlick, the issue was including the group=1