I encounter this type of graphs very often in scientific papers: example
Is this two plots made separately and joined in ggplot by gridding?
I encounter this type of graphs very often in scientific papers: example
Is this two plots made separately and joined in ggplot by gridding?
Welcome to Stack Overflow Irakli:
Here is some simple example of subplot using Plotly and subplots():
library(dplyr)
library(plotly)
# plot1
fig1 = plot_ly(data = mtcars, type = 'scatter', mode='markers', x = ~mpg, y= ~hp, name = "HP")
# plot2
fig2 = plot_ly(data = mtcars, type = 'scatter', mode= 'markers', x = ~mpg,y = ~drat, name="Drat")
subplot(fig1, fig2, shareX = T, nrows = 2)
Here is the output:
Another option for obtaining a similar plot can be achieved using cowplot package. Here is an example using the mtcars dataset.
library(cowplot)
library(ggplot2)
#Create first plot
p1<-ggplot(mtcars, aes(x = mpg,
y = disp)) +
geom_point()
#Create second plot
p2<-ggplot(mtcars, aes(x = mpg,
y = hp)) +
geom_point()+
#Remove x axis ticks, title and text
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_blank())
#Create a canvas and draw the two plots with different sizes.
#x and y define the plot's lower left corner where each plot will be set (0-1)
# width and height can be interpreted as the proportion (0-1) of the original
#plot to be used to draw each plot
p3<-ggdraw()+
draw_plot(p1,x=0,y=0,width=1,height=0.7)+
draw_plot(p2,x=0,y=0.7,width=1,height=0.3)
p3