Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何减少散点图周围的空白(使用R和ggplot2)_R_Ggplot2 - Fatal编程技术网

如何减少散点图周围的空白(使用R和ggplot2)

如何减少散点图周围的空白(使用R和ggplot2),r,ggplot2,R,Ggplot2,在我的散点图中,还有一些空白,我没有设法手动或使用xlim()命令或scale\u x\u discrete(limits=())减少它。我的代码: 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("K

在我的散点图中,还有一些空白,我没有设法手动或使用
xlim()
命令或
scale\u x\u discrete(limits=())
减少它。我的代码:

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))

谢谢你的帮助

你可以试试

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))]) 

然后您可以添加
+coord\u笛卡尔(ylim=c(min(d$R3),6))
来更改限制并接收此图


您能否提供绘制图所用的数据,以使您的示例具有可复制性?当然,我直接将其添加到问题中,并添加了一个链接。我希望它能工作。
R1
R3
都是整数。因此,尝试使用
scale\u x\u continuous
Ok@beetroot!>dput(doppellatings2_mit_ID_für_Stackoverflow)结构(列表(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,4,4,4,4,4,2,2,2,2,2,3,3,4,4),R3=c(2,3,3,3,3,2,3,3,3,4,4,4,4,3,4,4,4,4,4,4,4,4,4),row.names=c(NA,-17L),class=c(“tbl_-df”,“tbl”,“data.frame”)@Jimbou是正确的-您应该使用
scale\u x_continuous
。还可以尝试使用坐标笛卡尔(xlim=c(1:5),ylim=c(1:6))来指定限制而不是使用连续的比例来指定限制。感谢您的回答@Jimbou!我保持了scale_x_离散,因为我确信我的数据是离散的,但添加了坐标_笛卡尔(ylim=c(2,6),xlim=c(2,5)),它起了作用:参见[图表][1]。[1]:
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))])