首页 文章

如何使用R中的ggplot2并排绘制两个图

提问于
浏览
0

我有从不同方法获得的统计值的小数据帧 . you can download from here.数据集如下所示:

enter image description here

我需要刻面(两个绘图并排使用相同的y轴标签)两个RMSE.SD和MB变量图使用R中的ggplot2包,如下面的示例图所示 .

enter image description here

我编写了这段代码,用于绘制RMSE.SD变量的1个绘图 .

library(ggplot2)
comparison_korea <- read.csv("comparison_korea.csv")

    ggplot(data=comparison_korea, aes(R,X))+
      geom_point(color = "black", pch=17, alpha=1,na.rm=T, size=4)+
      labs(title = "", y = "")+

      theme(plot.title= element_text(hjust = 0.5,size = 15, vjust = 0.5, face= c("bold")),
            axis.ticks.length = unit(0.2,"cm") ,
            panel.border = element_rect(colour = "black", fill=NA, size=0.5),
            axis.text.x = element_text(angle = 0, vjust = 0.5, size = 14, hjust = 0.5,margin=margin(4,0,0,0), colour = "black"),
            axis.text.y = element_text(angle = 0, vjust = 0.5, size = 14, hjust = 1,margin=margin(0,5,0,0), colour = "black"),
            plot.margin = unit(c(1, 1.5, 1, 0.5), "lines"))

1 回答

  • 0

    你应该可以做这样的事情:

    library(ggplot2)
    
    ds <- read.csv("comparison_korea.csv")
    dat <- data.frame(labels = as.character(ds$X),
                      RMSE.SD = ds$RMSE.SD, 
                      MB = ds$MB)
    dat <- reshape2::melt(dat)
    
    ggplot(dat, aes(y = labels, x = value)) + 
      geom_point(shape = "+", size = 5) + 
      facet_wrap(~variable) + 
      xlab("value / reference (mm)") + 
      ylab("") + 
      theme_bw()
    

相关问题