简体   繁体   English

如何在R中使用ggplot更改散点图中的刻度线名称?

[英]How can I change the name of the tick marks in a scatterplot with ggplot in R?

In my scatterplot, I would like to replace the names of the tick marks (1 to 8) with the corresponding CEFR levels (A1.1 to B2.2) without changing the data frame. 在我的散点图中,我想用相应的CEFR级别(A1.1至B2.2)替换刻度线的名称(1至8),而无需更改数据框。

1 = A1.1,
2 = A1.2,
3 = A2.1,
4 = A2.2,
5 = B1.1,
6 = B1.2,
7 = B2.1,
8 = B2.2

My code: 我的代码:

ggplot(data =  doppelratings1_mit_ID,
  aes(x = R1 , y = R2)) +
  geom_jitter(shape=1, width = 0.05, height = 0.15) + 
  geom_smooth() +
  xlab("Rater 1") +
  ylab("Rater 2") +
  ggtitle("Korrelation zwischen Rater 1 und 2", paste("n = 19 Texte ")) +
  theme_bw(12)+
  geom_abline(intercept = 0, slope = 1)

I tried 我试过了

CEFR <- c("A1.2", "A2.2", "B1.2")

And then 接着

+ scale_x_discrete(labels= CEFR)

but then the tick marks disappeared. 但是刻度线消失了。

Thanks for your help! 谢谢你的帮助!

See my scatter plot: 看我的散点图:

两个评估人之间的相关性

Add this to your plot definition: 将此添加到您的绘图定义中:

tick_names <- c('A1.1', 'A1.2', ..., 'B2.2')

ggplot() + 
  ... +
scale_x_continuous(breaks = 1:8, labels = tick_names, limits = c(1, 8)) +
scale_y_continuous(breaks = 1:8, labels = tick_names, limits = c(1, 8))

I managed to display the scatter plot with the following code: 我设法用下面的代码显示散点图:

tick_names <- c("A1.1", "A1.2", "A2.1", "A2.2", "B1.1", "B1.2", "B2.1", "B2.2")
tick_names_x <- c("A1.1", "A1.2", "A2.1", "A2.2", "B1.1", "B1.2", "B2.1")

ggplot(data =  doppelratings1_mit_ID,
aes(x = R1 , y = R2)) +
geom_jitter(shape=1, width = 0.05, height = 0.15) + 
geom_smooth() +
xlab("Rater 1") +
ylab("Rater 2") +
ggtitle("Korrelation zwischen Rater 1 und 2", paste("n = 19 Texte ")) +
theme_bw(12)+
geom_abline(intercept = 0, slope = 1) +
scale_y_discrete(breaks = 1:8, labels = tick_names, limits = c(1:8)) +
scale_x_discrete(breaks = 1:7, labels = tick_names_x, limits = c(1: 7))

Thanks for you help! 感谢您的帮助! See the image: correlation between two raters 如图: 两个评估者之间的相关性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM