【发布时间】:2015-09-13 14:49:45
【问题描述】:
我正在尝试使用 ggplot2 复制以下图表
我想对该图表进行的一项更改是为每个点及其标签赋予颜色。到目前为止,这是我尝试过的:
library(ggplot2)
library(directlabels)
Z <- c("Label1", "Label2", "Label3", "Label4", "Label5", "Label6", "Label7",
"Label8", "Label9", "Label10", "Label11", "Label12", "Label13", "Label14",
"Label15", "Label16", "Label17", "Label18", "Label19", "Label20", "Label21",
"Label22", "Label23", "Label24")
X <- c(10.32582421, 9.772686421, -13.99202201, 3.803952545, 7.775395482,
-11.82234956, -24.27906403, -6.864457678, -24.62853773, 15.3562638,
-6.476057462, 9.576414602, -5.504090215, 29.74512913, 9.046116821,
15.79954557, -39.61679645, -0.90307239, 21.12503086, 15.30221473,
13.40781808, -6.803226537, -4.045907666, -0.134057007)
Y <- c(0.037608141, 0.010581738, 0.117730985, 0.022347258, 0.069347278,
0.026699666, 0.028739498, 0.040611306, 0.036626248, 0.034854158,
0.039310836, 0.03122964, 0.009422296, 0.021935924, 0.050006846,
0.036285691, 0.016796701, 0.057764277, 0.028421772, 0.042726693,
0.037513217, 0.058422072, 0.066859355, 0.078158403)
mychart <- data.frame(Z, X, Y)
q <- ggplot(mychart, aes(X, Y)) + geom_point(aes(colour = Z)) + theme_bw()
direct.label(q)
我得到以下结果:
我无法弄清楚三件事:
- 我想删除灰色象限线。
- 我想移动坐标轴,使它们在图表中居中,图分布在 4 个象限中。
- 我想减小标签字体大小 - 我怀疑这就是为什么它们中的一些最终没有接近它们的点。
【问题讨论】:
-
(1)
help("theme")。 (2) 要么查看geom_vline(),要么在没有边距的情况下分面; (3)help("apply.method")或使用geom_text()手动定位vsdirectlabel; (4) 你的答案是不可重复的。 -
另见在线help for theme