【问题标题】:ggplot chart, x=date, y= value, valueggplot 图表,x=日期,y=值,值
【发布时间】:2014-07-03 18:02:29
【问题描述】:

我有这个测试数据:

      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。有人有想法吗?

感谢和最好的问候!

【问题讨论】:

  • 到目前为止你尝试过什么?顺便说一句,因为您将字符 (U) 与数字数据一起存储在几列中,它们将被转换为character,这对于绘图没有意义。你是指NA吗?
  • 请参阅我对早期问题的回答:1 / 2

标签: r ggplot2


【解决方案1】:
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')

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))

【讨论】:

  • 非常感谢...你能发一个例子吗?
  • @user3181885 恐怕你不能没有频率数据。您为每个测试提供了一个条目。 geom_path 代替?见ggplot docs
  • 嗯没有机会用我的测试日期创建这样的图表-->(例如)link
  • 是的,带有 geom_path(aes(colour = variable, group = variable)) 并且没有分面。
猜你喜欢
  • 2014-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-10
  • 2017-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多