0

我有这个数据框,称为测试。它有 3 列,DATE, USED_CORES, RELATIVE_PERCENT。我想创建一个 ggplot 图,我想DATE在 x 轴、y 轴RELATIVE_PERCENT和y 轴USED_CORES右侧显示。

这是我的数据框:

dput(head(test,30))  

structure(list(DATE = structure(c(1364359560, 1364359590, 1364359620, 
1364359650, 1364359680, 1364359710, 1364359740, 1364359770, 1364359800, 
1364359830, 1364359860, 1364359890, 1364359920, 1364359950, 1364359980, 
1364360010, 1364360040, 1364360070, 1364360100, 1364360130, 1364360160, 
1364360190, 1364360220, 1364360250, 1364360280, 1364360310, 1364360340, 
1364360370, 1364360400, 1364360430), class = c("POSIXct", "POSIXt"
), tzone = ""), USED_CORES = c(2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 
2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.24, 2.4, 2.4, 2.4, 2.4, 2.4, 
2.24, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.56), 
    RELATIVE_PERCENT = c(15, 15, 15, 15, 15, 15, 15, 15, 15, 
    15, 15, 15, 14, 15, 15, 15, 15, 15, 14, 15, 15, 15, 15, 15, 
    15, 15, 15, 15, 15, 16)), .Names = c("DATE", "USED_CORES", 
"RELATIVE_PERCENT"), row.names = c(NA, 30L), class = "data.frame")

我可以这样做以DATE在 xaxis 和 yaxisRELATIVE_PERCENT上显示:

ggplot(test, aes(DATE, RELATIVE_PERCENT)) + 
      geom_point(colour="blue", size=1) + theme_bw()

如何USED_CORES在 y 轴的右侧显示?

4

1 回答 1

1

显然这在 ggplot2 中是不可能的,这是有充分理由的。看看这个问题:

绘制 2 个 y 轴,左侧一个 y 轴,右侧另一个 y 轴

尤其是在接受答案的 wiki-link 上:

http://rwiki.sciviews.org/doku.php?id=tips:graphics-ggplot2:aligntwoplots

于 2013-05-23T13:51:27.127 回答