Home > OS >  ggplot2 Missing y-axis labels
ggplot2 Missing y-axis labels

Time:12-15

Morning, I have a little problem with my ggplot graph.

For some reason, I can't see right now, the y axis ticks and numbers are missing. 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).

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

Plot

Would be great if someone could see the problem; I'm going blind by now. Many thanks!!

CodePudding user response:

Shouldn't your y axis be continuous?

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))
  • Related