简体   繁体   中英

How to reduce the white space around a scatter plot (using R and ggplot2)

In my scatterplot, there is some empty space left and I haven't managed to reduce it manually or with the xlim() command nor with scale_x_discrete(limits=()) . My code:

ggplot(data = doppelratings2_mit_ID, 
aes(x = R1, y = R3)) +
geom_jitter(shape = 1, width = 0.1, height = 0.1) + 
geom_smooth()+
xlab("Rater 1") +
ylab("Rater 3") +
ggtitle("Korrelation zwischen Rater 1 und 3", paste("n = 17 Texte ")) +
theme_bw(12)+
geom_abline(intercept = 0, slope = 1)+
scale_x_discrete(breaks = 1:5, labels = tick_names_5, limits = c(1:5))+
scale_y_discrete(breaks = 1:6, labels = tick_names_6, limits = c(1:6))

And the data :

> dput(doppelratings2_mit_ID_für_Stackoverflow)
structure(list(ID = c(6584209, 6598108, 6584103, 6552101, 6608303, 
6656213, 9734115, 9554201, 9554108, 9604202, 6660108, 6520103, 
6726215, 6574106, 9762121, 9688202, 9576108), R1 = c(2, 3, 2, 
3, 3, 2, 3, 4, 4, 5, 4, 4, 2, 2, 3, 4, 4), R3 = c(2, 3, 3, 3, 
2, 2, 3, 5, 5, 6, 4, 4, 2, 2, 3, 3, 4)), row.names = c(NA, -17L
), class = c("tbl_df", "tbl", "data.frame"))

Thanks for your help!

在此处输入图片说明

You can try

ggplot(data = d, 
       aes(x = R1, y = R3)) +
  geom_jitter(shape = 1, width = 0.1, height = 0.1) + 
  geom_smooth()+
  xlab("Rater 1") +
  ylab("Rater 3") +
  ggtitle("Korrelation zwischen Rater 1 und 3", paste("n = 17 Texte ")) +
  theme_bw(12)+
  geom_abline(intercept = 0, slope = 1) + 
  scale_x_continuous(breaks = min(d$R1):max(d$R1), labels = LETTERS[1:length(min(d$R1):max(d$R1))]) +
  scale_y_continuous(breaks = min(d$R3):max(d$R3), labels = LETTERS[1:length(min(d$R3):max(d$R3))]) 

在此处输入图片说明

Then you can add + coord_cartesian(ylim=c(min(d$R3),6)) to change the limits and to recieve this plot.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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