R ggplot2中缺少x轴组名称
我试图输出一个图形,但无法获得x轴上的组名称标签 我的文件如下所示(共有28组用于描述,4000组用于表型): 我的代码如下所示:R ggplot2中缺少x轴组名称,r,ggplot2,R,Ggplot2,我试图输出一个图形,但无法获得x轴上的组名称标签 我的文件如下所示(共有28组用于描述,4000组用于表型): 我的代码如下所示: ylim <- abs(floor(log10(min(phe$p)))) + 2 nCHR <- length(unique(phe$description)) axis.set <- phe %>% group_by(description) %>% summarize(center = n() / 2) sig=0
ylim <- abs(floor(log10(min(phe$p)))) + 2
nCHR <- length(unique(phe$description))
axis.set <- phe %>%
group_by(description) %>%
summarize(center = n() / 2)
sig=0.05/nrow(phe)
phewasplot <- ggplot(phe, aes(x=phenotype, y=-log10(p), label=description, color=as.factor(description), size=-log10(p))) +
geom_point(alpha=0.75) +
geom_hline(yintercept = -log10(sig), color = "grey40", linetype = "dashed") +
scale_x_discrete(label = axis.set$description, breaks = axis.set$center) +
scale_y_continuous(expand = c(0,0), limits = c(0, ylim)) +
scale_size_continuous(range = c(0.5,3)) +
labs(x = "Phenotypes",
y = "-log10(p)") +
theme_minimal() +
theme(
legend.position = "none",
panel.border = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(angle = 90, size = 8, vjust = 0.5)
)
ylim是否签出该软件包?默认情况下,ggplot2
将按字母顺序排列x轴,除非映射的美学是一个因素。然后它将按级别顺序排列x轴。但要对x轴标签进行分组,需要使用另一个变量和forcats R包中的函数fct_reorder()
。这些组合可以得到您想要的结果,但如果没有最低限度的工作示例,我无法编写一个正式的答案。转到技巧#5:您签出包了吗?默认情况下,ggplot2
将按字母顺序排列x轴,除非映射的美学是一个因素。然后它将按级别顺序排列x轴。但要对x轴标签进行分组,需要使用另一个变量和forcats R包中的函数fct_reorder()
。这些方法的结合可以得到你想要的结果,但如果没有一个最低限度的工作示例,我无法编写一个正式的答案。请转到技巧5:
ylim <- abs(floor(log10(min(phe$p)))) + 2
nCHR <- length(unique(phe$description))
axis.set <- phe %>%
group_by(description) %>%
summarize(center = n() / 2)
sig=0.05/nrow(phe)
phewasplot <- ggplot(phe, aes(x=phenotype, y=-log10(p), label=description, color=as.factor(description), size=-log10(p))) +
geom_point(alpha=0.75) +
geom_hline(yintercept = -log10(sig), color = "grey40", linetype = "dashed") +
scale_x_discrete(label = axis.set$description, breaks = axis.set$center) +
scale_y_continuous(expand = c(0,0), limits = c(0, ylim)) +
scale_size_continuous(range = c(0.5,3)) +
labs(x = "Phenotypes",
y = "-log10(p)") +
theme_minimal() +
theme(
legend.position = "none",
panel.border = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(angle = 90, size = 8, vjust = 0.5)
)