[英]Multiple lines in ggscatter plot
嗨,我目前正在我的社会学学士中学习 R 编程,但我遇到了一个问题,即我无法在分散的 plot 中实现两条回归线。 到目前为止,我编写的代码如下:
#Value 1 and 2 from the first country
Lrscaleger <- c(4.535469,4.53125,4.515967,4.500684,4.446576,4.392469,4.390175,4.387881)
DomMusGer <- c(6,10,4,14,13,10,8,17)
GER <- data.frame(Lrscaleger,DomMusGer)
#Value 1 and 2 from the second country
Lrscalech <- c(5.136263,5.153846,5.148803,5.143759,5.103913,5.064067,5.079669,5.095272)
DomMusCH <- c(2,3,2,2,1,0,2,2)
CH <- data.frame(Lrscalech,DomMusCH)
#Scatterplot for Country Nr. 1
ggscatter(GER,
x = "Lrscaleger",
y="DomMusGer",
color="black",
add="reg.line",
xlab = "Politische Ausrichtung von 0(Links) - 10(Rechts)",
ylab= "Künstler:innen einheimisch")
#Scatterplot for Country Nr. 2
ggscatter(CH,
x = "Lrscalech",
y = "DomMusCH",
color="black",
add="reg.line",
xlab = "Politische Ausrichtung von 0(Links) - 10(Rechts)",
ylab= "Künstler:innen einheimisch")
TBMK 恐怕这是不可能通过ggpubr::ggscatter
。 我检查了文档,找不到一个选项,例如 map 上色器的第三个变量colorer... Instead I would suggest to simply use
ggplot2`。
为此,您首先必须使用例如dplyr::bind_rows
组合您的国家数据集。 但是,由于数据集中的列具有与县代码相对应的后缀,我们首先必须rename
这些列。
library(ggplot2)
library(dplyr)
library(ggpubr)
CH <- rename(CH, Lrscale = Lrscalech, DomMus = DomMusCH)
GER <- rename(GER, Lrscale = Lrscaleger, DomMus = DomMusGer)
CH_GER <- list(CH = CH, GER = GER) %>%
dplyr::bind_rows(.id = "country")
ggplot(CH_GER, aes(Lrscale, DomMus, color = country)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
ggpubr::theme_pubr() +
labs(x = "Politische Ausrichtung von 0(Links) - 10(Rechts)",
y= "Künstler:innen einheimisch")
#> `geom_smooth()` using formula 'y ~ x'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.