【发布时间】:2021-08-31 10:51:25
【问题描述】:
我正在制作散点图,并想用符号替换 y 轴的数字。具体来说,我想将 20 替换为减号,将 0 替换为加号。
我看过this response,但我创建 y 轴的方式有点不同。
谢谢。
这是我的绘图代码:
library(tidyverse)
ggplot(exampledf, aes(x = male_diff, y = index, color = as.factor(expt_in_ms))) +
geom_point(aes(alpha = 0.5, size = 3)) +
geom_point(aes(x = female_diff),alpha = 0.8, shape =24, size = 5) +
scale_y_continuous(breaks = 1:nrow(exampledf), labels = exampledf$nloci) +
xlab("difference in proportion") +
ylab("correlation") +
geom_vline(
xintercept = 0,
color = 'black',
linetype = 'dashed',
alpha = .5
) +
theme_minimal() + theme(text = element_text(size = 12)) + guides(alpha=FALSE) + guides(size=FALSE) +
guides(shape = FALSE) + guides(color = FALSE)
这是绘图代码中名为exampledf的数据集:
structure(list(male_diff = c(0.4668, -0.03299, 0.702, -0.11544,
0.689, 0.511, -0.0725, -0.12844, -0.0827, 0.6515, -0.01077, 0.006,
0.0041, -0.00856, 0.4181, -0.02765), female_diff = c(-0.459,
0.022, -0.155, 0.00800000000000001, -0.156, -0.326, -0.0224,
0.00700000000000001, 0.0399999999999999, 0.2182, -0.08458, 0.8844,
-0.8459, 0.122, -0.506, 0.03), expt_in_ms = c(1, 1, 2, 2, 3,
3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4), nloci = c(0, 20, 0, 20, 0,
0, 0, 20, 20, 20, 0, 20, 0, 20, 0, 20), index = 1:16), row.names = c(NA,
-16L), class = c("tbl_df", "tbl", "data.frame"))
【问题讨论】: