Orpheus
Orpheus

Reputation: 329

How to facet two plots side by side using ggplot2 in R

I have small data frame of statistical values obtained from different method. you can download from here.Dataset is look like this:

enter image description here

I need to facet (two plot side by side with same y axis labels) two plot of RMSE.SD and MB variable using ggplot2 package in R like the following example figure.

enter image description here

I wrote this code for plotting 1 plot for RMSE.SD variable.

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")) 

Upvotes: 1

Views: 4787

Answers (1)

royr2
royr2

Reputation: 2289

You should be able to do something like this:

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()

Upvotes: 1

Related Questions