library(ggpubr)
## 载入需要的程辑包:ggplot2
# Create a scatter plot
p <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width",
color = "Species", palette = "jco",
ggtheme = theme_minimal())
p

p1 <- ggplot(data=iris, aes(x=Sepal.Width))+
geom_histogram(binwidth=0.2, color="black", aes(fill=Species))
# Extract the legend. Returns a gtable
leg <- get_legend(p)
# Convert to a ggplot and print
as_ggplot(leg)
library(grid)
library(cowplot)
##
## 载入程辑包:'cowplot'
## The following object is masked from 'package:ggpubr':
##
## get_legend
grid.draw(leg)

ggdraw() +
draw_plot(p1, x = 0, y = 0, width = 1, height = 1) +
draw_plot(leg, x = 0.31, y =-0.25, width = 1, height = 1) +
draw_plot(leg, x = 0.31, y =0.33, width = 1, height = 1)
