R 如何复制三个相邻的图,其中两个图上有边缘图?
这就是我想要实现的目标: 我正试图使用ggplot复制这些图的主题,我在网上搜索了一些文章和问题,向我展示了如何分配这些图的正确大小和位置,以及如何分配紧点形状,我发现很少有文章讨论改变位置,我尝试了以下方法:R 如何复制三个相邻的图,其中两个图上有边缘图?,r,R,这就是我想要实现的目标: 我正试图使用ggplot复制这些图的主题,我在网上搜索了一些文章和问题,向我展示了如何分配这些图的正确大小和位置,以及如何分配紧点形状,我发现很少有文章讨论改变位置,我尝试了以下方法: d1<-read.csv("./data/games.csv") library(ggplot2) library(dplyr) d1 %>% filter(winner != "draw") %>% ggplo
d1<-read.csv("./data/games.csv")
library(ggplot2)
library(dplyr)
d1 %>%
filter(winner != "draw") %>%
ggplot(aes(x=cream_rating, y=charcoal_rating, color = winner, shape = winner)) +
# Map winner on color. Add some transparency in case of overplotting
geom_point(alpha = 0.2, na.rm = TRUE) +
# Just a guess to add the cross: Add geom_pints with one variable fixed on its mean
# Should "draw"s be colored or dropped?
scale_color_manual(values = c(cream = "seagreen4", charcoal = "chocolate3")) +
scale_shape_manual(values = c(cream = 16, charcoal = 17)) +
ggtitle("Rating of Cream vs Charcoal") +
xlab("rating of cream") + ylab("rating of charcoal")+ theme_classic() + theme(plot.title = element_text(hjust = 0.5))
p.1<-ggplot(d1, aes(x=cream_rating, y=charcoal_rating)) +
# Map winner on color. Add some transparency in case of overplotting
geom_point(aes(color = winner), alpha = 0.2) +
# Add the cross: Add geom_pints with one variable fixed on its mean
geom_point(aes(y = mean(charcoal_rating), color = winner), alpha = 0.2) +
scale_shape_manual(values=c(16, 17)) +
# "draw"s should be dropped and removed from the title
scale_color_manual(values = c(cream = "seagreen4", charcoal = "chocolate3", draw = NA)) +
ggtitle("Rating of Cream vs Charcoal") +
xlab("rating of cream") + ylab("rating of charcoal") + theme_classic() + theme(plot.title = element_text(hjust = 0.5))
p.01<-ggplot(d1, aes(x=cream_rating, y=charcoal_rating)) +
# Map winner on color. Add some transparency in case of overplotting
geom_density2d(aes(color = winner), alpha = 0.2) +
# Add the cross: Add geom_pints with one variable fixed on its mean
scale_shape_manual(values=c(16, 17, 0)) +
# "draw"s should be dropped and removed from the title
scale_color_manual(values = c(cream = "seagreen4", charcoal = "chocolate3", draw = "blue")) +
ggtitle("Rating of Cream vs Charcoal") +
xlab("rating of cream") + ylab("rating of charcoal") + theme_classic() + theme(plot.title = element_text(hjust = 0.5))
plot.1<-p.1
plot.02<-ggExtra::ggMarginal(p.01, type = "density",
margins = 'both',
size = 5,
groupColour = TRUE,
groupFill = TRUE
)
plot.02
require(gridExtra)
plot.1<-p.1
plot.2<-ggExtra::ggMarginal(p.1, type = "histogram")
grid.arrange(plot.1, plot.2, ncol=3)
plot.02
library(cowplot)
theme_set(theme_cowplot())
plot.1<-p.1
plot.2<-ggExtra::ggMarginal(p.1, type = "histogram")
plot.02
plot_grid(plot.1, plot.2, plot.02, labels = "AUTO")
cowplot::plot_grid(plot.1, plot.2, plot.02, labels = "AUTO")
library(magrittr)
library(multipanelfigure)
figure1 <- multi_panel_figure(columns = 2, rows = 1, panel_label_type = "none")
# show the layout
figure1
figure1 %<>%
fill_panel(plot.1, column = 1, row = 1) %<>%
fill_panel(plot.2, column = 2, row = 1) %<>%
fill_panel(plot.02, column= 3, row = 1) %<>%
figure1
多亏了@Stefan的建议(这对我帮助很大)。你的链接图片失去了谢谢@max!我用图片更新了问题。
structure(list(rated = c(FALSE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE), turns = c(13L, 16L, 61L, 61L, 95L,
5L, 33L, 9L, 66L, 119L), victory_status = structure(c(3L, 4L,
2L, 2L, 2L, 1L, 4L, 4L, 4L, 2L), .Label = c("draw", "mate", "outoftime",
"resign"), class = "factor"), winner = structure(c(2L, 1L, 2L,
2L, 2L, 3L, 2L, 1L, 1L, 2L), .Label = c("charcoal", "cream",
"draw"), class = "factor"), increment_code = structure(c(3L,
7L, 7L, 5L, 6L, 1L, 1L, 4L, 2L, 1L), .Label = c("10+0", "15+0",
"15+2", "15+30", "20+0", "30+3", "5+10"), class = "factor"),
cream_rating = c(1500L, 1322L, 1496L, 1439L, 1523L, 1250L,
1520L, 1413L, 1439L, 1381L), charcoal_rating = c(1191L, 1261L,
1500L, 1454L, 1469L, 1002L, 1423L, 2108L, 1392L, 1209L)), row.names = c(NA,
10L), class = "data.frame")