如何使用日期下的值创建y轴而不操作Excel中的数据?
Client 12/21/2015 12/22/2015 12/26/2015
client1 50 60 59
client2 50 60 60
client3 51 60 61
client4 53 60 62
client5 55 60 63
client6 55 60 64
client7 51 60 65
答案 0 :(得分:0)
您必须将日期从宽格式转换为长格式。这可以使用gather
完成,如评论中所示:
library(tidyverse)
df <- read.table(header=T, check.names=F, text="
Client 12/21/2015 12/22/2015 12/26/2015
client1 50 60 59
client2 50 60 60
client3 51 60 61
client4 53 60 62
client5 55 60 63
client6 55 60 64
client7 51 60 65")
df <- gather(df, date, value, -Client)
然后
ggplot(df, aes(x = Client, y=value, fill = date)) +
geom_col()
或者
ggplot(df, aes(x = as.Date(date, "%m/%d/%Y"), y = value, color = Client)) +
geom_line() +
geom_point()