ggplot chart,x = date,y = value,value

时间:2014-05-15 10:32:40

标签: r ggplot2

我有这个测试数据:

      date      cpu_user cpu_id test1 test2 test3 test4
1 1386716402        U      U     U     U     U    31
2 1386716702        0   0.06 99.95  0.02 91.93    29
3 1386717002     0.01   0.04 99.97  0.03 19.46    29
4 1386717302     0.01   0.05 99.96  0.04 92.54    29
5 1386717602        0   0.04 99.97  0.04     U    29
6 1386717902        0   0.05 99.96  0.02 99.86    29

我想要一个freqpoly图表,其中日期为x,另一个(cpu_udercpu_id,....)位于y。有人有个主意吗?

谢谢,最诚挚的问候!

1 个答案:

答案 0 :(得分:0)

d <- read.table(text=readClipboard(), header=TRUE, stringsAsFactors = T,
                na.strings = 'U')
df <- melt(d, id.var='date')
ggplot(aes(x=date, y=value), data = df) +
  geom_bar(aes(fill = variable), stat = 'identity', position = 'dodge')

bar chart

ggplot(aes(x=factor(date), y=value), data = df) +
  geom_bar(stat = 'identity', position = 'dodge') +
  facet_grid(variable~., scales = 'free_y', drop = F) +
  theme(axis.text.x = element_text(angle = 45, vjust = 1.1, hjust = 1.05))

faceting option