【问题标题】:issue with ggplot2/geom_line - subjets datasets plotted erroneously jointlyggplot2/geom_line 的问题 - subjets 数据集错误地联合绘制
【发布时间】:2018-10-07 14:34:16
【问题描述】:

我对以下数据框有疑问,尽管我遵循了线图的标准示例。 如图所示,三个科目的虚拟时间课程中的两个是联合绘制的,而不是单独绘制的

library(tidyverse)

blub <- structure(list(time = seq(0,10,by=1), 
                     sub1 = seq(10,20,by=1), 
                     sub2 = seq(20,30,by=1), 
                     sub3 = seq(30,40,by=1)), 
                row.names = c(NA, -11L), 
                class = "data.frame")

bluba <- gather(data = blub, key=subjects, value=value, 2:ncol(blub))

basic <- c("N","P","P")
statusArray <- rep(basic,each=11)

bluba$status <- statusArray

print(ggplot(data=bluba, 
             aes(x=time,y=value, color=status)) +
             geom_line())

任何 cmets 将不胜感激!

【问题讨论】:

    标签: r dataframe ggplot2


    【解决方案1】:

    group添加到aes以指定线路的连接

    print(ggplot(data=bluba, 
                 aes(x=time,y=value, color=status, group = subjects)) +
            geom_line())
    

    【讨论】:

      【解决方案2】:

      你可以使用linetype = subjects

         bluba %>% 
            ggplot(aes(x=time,y=value, color=status, linetype=subjects)) +
            geom_line()
      

      【讨论】:

      • 很有趣,但有超过 100 个主题,www 的解决方案效果更好
      猜你喜欢
      • 1970-01-01
      • 2021-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-05
      相关资源
      最近更新 更多