[英]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.