【问题标题】:R ggplot geom_line() doesn't give the wanted result [duplicate]R ggplot geom_line() 没有给出想要的结果[重复]
【发布时间】:2020-10-07 21:28:56
【问题描述】:

我是 R 新手,对 ggplot2 有一些问题。 我尝试使用此代码在 ggplot 上绘制 geom_line:

gplot(shm_data ,aes(X, Y, fill= Count)) + 
  geom_tile(aes(X,Y,alpha=Count))+
  scale_fill_gradientn(colours=c("yellow","orange","red"),na.value = NA,guide=FALSE)+
  scale_y_continuous(trans = "reverse")+
  scale_alpha(guide=FALSE,range = c(0.25,1))+
  ggtitle(paste0("heat map of ",
                 substring(session_name,1, regexpr("-", session_name) - 1)))+
  geom_line(data=smooth_cm,aes(x,y),inherit.aes=FALSE,na.rm=TRUE)

代码在我的 ggplot 上生成了这个图:

我希望它成为我的 ggplot 的常规情节, 看起来像这样:

上图的代码是:

plot(y~x , ylim = rev(range(y,na.rm=TRUE)),type='l') 

我无法理解这个问题,并提前感谢您抽出时间回答我的问题。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    我的猜测(缺少数据)是(错误的)涂鸦是它在框架中的顺序,而与 x-axis 变量的顺序无关。请改用geom_path

    gplot(shm_data ,aes(X, Y, fill= Count)) + 
      geom_tile(aes(X,Y,alpha=Count))+
      scale_fill_gradientn(colours=c("yellow","orange","red"),na.value = NA,guide=FALSE)+
      scale_y_continuous(trans = "reverse")+
      scale_alpha(guide=FALSE,range = c(0.25,1))+
      ggtitle(paste0("heat map of ",
                     substring(session_name,1, regexpr("-", session_name) - 1)))+
      geom_path(data=smooth_cm,aes(x,y),inherit.aes=FALSE,na.rm=TRUE)
    

    来自?geom_path

    geom_path() 按照观察值在数据中出现的顺序连接它们。 geom_line() 按照 x 轴上的变量顺序连接它们。

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 1970-01-01
      • 2019-08-12
      • 2013-10-26
      • 2021-03-02
      • 2017-08-25
      • 2021-12-10
      • 2018-10-17
      • 2019-11-27
      相关资源
      最近更新 更多