【问题标题】:ggplot2 Missing y-axis labelsggplot2 缺少 y 轴标签
【发布时间】:2022-01-18 10:56:11
【问题描述】:

早上好,我的ggplot 图表有点问题。

由于某种原因,我现在看不到 y 轴刻度和数字。也许,我在这里遗漏了一些非常明显的东西,或者它在我的设置中。 牙齿生长数据集并不真正适合图表,但您仍然可以看到问题(通常包含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

如果有人能看到问题就好了;我现在要瞎了。非常感谢!!

【问题讨论】:

  • 因为映射到 y 上的变量看起来像一个数字:尝试使用 scale_y_continuous(name ="Name") 而不是 scale_y_discrete。

标签: r ggplot2 boxplot axis-labels


【解决方案1】:

你的 y 轴不应该是连续的吗?

scale_y_continuous(name ="Name")

然后您可以根据需要添加限制和刻度位置:

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

【讨论】:

  • 因为羞耻,我准备把自己扔进河里了......非常感谢,当然就是这样!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
相关资源
最近更新 更多