图形微调:学习如何压缩x轴

时间:2018-02-21 01:40:26

标签: r ggplot2

我是R的新手并且一直在尝试使用ggplot创建图表。我已经取得了很多进展并创建了以下图片:

Graph image

我的问题更多的是关于图表本身的微调。目前,我在x轴上有一个值,并希望" trim"图表的两侧可以更小。我一直在网上阅读并试图找出一种方法来使用scale_x_continuous()来定义X,但它似乎不起作用。有没有办法以这种方式编辑图形的尺寸?

<ggplot(positivevalues, aes(x=Valence, y=Value, shape=Categories, color=Categories)) + geom_point(aes(size=5), stat="identity", position
= position_jitter(w = 0.02, h = 0.1)) + labs(title="X", x="EHR", y="Number of Times Codes Applied", subtitle="X") + theme_bw() +
ylim(min=0,max=50) + scale_x_continuous(limits=c(0,0)) +
scale_y_continuous(limits =c(0, 50)) + guides(colour =
guide_legend(override.aes = list(size=4))) + scale_shape_manual(values
= c(17, 18, 16, 8, 15, 9)) + scale_color_manual(values = c("darkgreen", "darkorange", "blue", "black", "darkred",
"blueviolet")) + scale_color_manual(values = c("darkgreen",
"darkorange", "blue", "black", "darkred", "blueviolet")) +labs(x= "   
Positive     \n X") + theme(axis.text=element_text(size=9))>

1 个答案:

答案 0 :(得分:0)

library(ggplot2)
positivevalues <- data.frame(Valence=rep("n=p",6), Value=c(0.1,0.5,2,2,18,35), 
                             Categories=LETTERS[1:6])

set.seed(123)
ggplot(positivevalues, aes(x=as.numeric(Valence), y=Value, 
                           shape=Categories, color=Categories)) + 
geom_point(aes(size=5), stat="identity", position=position_jitter(w = 0.02, h = 0.1)) + 
labs(title="X", x="EHR", y="Number of Times Codes Applied", subtitle="X") + theme_bw() +
scale_x_continuous(limits=c(0.95,1.05), breaks=1, labels="n=p") +
scale_y_continuous(limits =c(0, 50)) + 
guides(colour = guide_legend(override.aes = list(size=4))) + 
scale_shape_manual(values= c(17, 18, 16, 8, 15, 9)) + 
scale_color_manual(values = c("darkgreen", "darkorange", "blue", 
                              "black", "darkred", "blueviolet")) + 
labs(x= "Positive     \n X") + theme(axis.text=element_text(size=9)) +
theme(legend.position="none")

enter image description here