【问题标题】:GGplot - multiple lines for same column value based on other column - no facetsGGplot - 基于其他列的同一列值的多行 - 没有方面
【发布时间】:2013-06-18 23:56:23
【问题描述】:

我有一个包含三组的数据框。我必须按组和状态为某些指标绘制线——这无法分面。所有线必须一起出现在同一个图表中。每个组将有一种线颜色 - 和两条线 - 基于布尔状态的一条虚线和一条实线,即,对于三个组,将有六条线。

类似的示例数据框:

Data <- data.frame(
    groupname = sample(c("group1", "group2", "group3"), 100, replace = TRUE),
    timeblock = sample(1:10, 100, replace = TRUE),
    supermetric = sample(1:25, 100, replace = TRUE),
    boolstatus = sample(0:1, 100, replace = TRUE) )

到目前为止,我没有成功尝试过:基于组进行拆分并调用嵌套元素,以及尝试使用较小的数据框创建各种层(这与所有融化数据的建议背道而驰)。 错误包括:

Error: Aesthetics must either be length one, or the same length as the dataProblems:group1df$supermetric

Error: ggplot2 doesn't know how to deal with data of class list

【问题讨论】:

    标签: r graph ggplot2


    【解决方案1】:

    根据描述,我试过了

    ggplot(Data, aes(x=timeblock, y=supermetric, 
                     group=interaction(boolstatus, groupname),
                  colour=groupname, linetype=factor(boolstatus))) +
      geom_line()
    

    但我不知道这是否是你想要的情节。

    【讨论】:

    • 就是这样。现在,我需要平滑线条。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    • 2023-03-15
    • 2022-01-10
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多