简体   繁体   English

ggplot2 缺少 y 轴标签

[英]ggplot2 Missing y-axis labels

Morning, I have a little problem with my ggplot graph.早上,我的ggplot图有点问题。

For some reason, I can't see right now, the y axis ticks and numbers are missing.由于某种原因,我现在看不到 y 轴刻度和数字。 Maybe, I'm missing something really obvious here or it's something in my settings.也许,我在这里遗漏了一些非常明显的东西,或者它在我的设置中。 The toothgrowth dataset does not really fit the graph, but you can still see the problem (normally facet_wrap is included, but it does not work with this dataset).牙齿生长数据集并不真正适合图表,但您仍然可以看到问题(通常包含facet_wrap ,但不适用于此数据集)。

library(tidyverse)
library(ggbeeswarm)
library(gghalves)
library(tidyr)
library(ggplot2)
library(ggpubr)

theme_set(theme_bw(16))

data <- ToothGrowth

a<- ggplot(data, aes(x=supp, y=len)) +
geom_half_boxplot(
data = data %>% filter(supp=="OJ"), 
aes(x = supp, y = len,  fill=supp), outlier.color = NA) +
scale_fill_manual(values=c("#F2F2F2", "#999999"))+

geom_half_boxplot(
data = data %>% filter(supp=="VC"), 
aes(x = supp, y = len, fill=supp), side = "r", outlier.color = NA) +

geom_line(aes(group=supp, colour = supp), position = position_dodge(0.2), alpha = 0.3) +
geom_point(aes(group=supp, colour = supp),size=1,shape=21, position = position_dodge(0.2)) +
scale_color_manual(values=c("chartreuse3", "yellow2",
                          "firebrick3"))+
#  facet_wrap(~ supp)+
#  theme(
#    strip.background = element_blank(),
#    strip.text.x = element_blank())+
theme(plot.margin=unit(c(0,0,0,0),"cm"))+
scale_y_discrete(name ="Name")+
theme(text = element_text(size=11))+
theme(legend.position = "none")

a

阴谋

Would be great if someone could see the problem;如果有人能看到问题,那就太好了; I'm going blind by now.我现在要瞎了。 Many thanks!!非常感谢!!

Shouldn't your y axis be continuous?你的y轴不应该是连续的吗?

scale_y_continuous(name ="Name")

Then you can add the limits and ticks positions as you want:然后,您可以根据需要添加限制和刻度位置:

scale_y_continuous(name="Name",limits=c(min,max), breaks=c(a,b,c,d))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM