微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更改GGPlot2轴的长度而不更改轴限制

如何解决更改GGPlot2轴的长度而不更改轴限制

我制作了以下Box-Whisker图,以在R中显示GGPlot2的数据集:

enter image description here

不过,您可能会注意到,该图看起来非常“高大”。有没有办法在不改变比例的情况下进一步压缩y轴的长度,这样我的数据就不会被截断?

我的代码如下:

healthy.control <- c(96.8,96.2,94.3,94.0,95.5,94.7)
healthy.exp <- c(median(79.64,79.13,79.04,79.49,79.51,79.90),median(78.98,78.35,78.57,78.78,78.45,78.63),median(77.12,77.90,77.43,77.07,77.85,77.81),median(76.59,76.82,76.64,77.13,77.16,76.66),median(78.00,78.26,78.08,77.79,78.34),median(76.96,76.83,77.88,77.93,77.69,77.30))
  
adhd.control <- c(58.4,59.1,53.7,56.3,53.1,54.3)
adhd.exp <- c(median(49.12,48.39,48.68,48.50,48.00,48.32),median(48.96,48.94,49.24,49.30,48.78,49.15),median(44.97,45.24,45.26,45.00,44.87,45.02),median(46.95,47.05,47.04,46.80,47.70,46.97),median(44.28,44.20,44.42,44.37,44.43,44.67),median(45.04,45.56,44.76,45.50,45.02))

fig.data <- c(adhd.control,adhd.exp,healthy.control,healthy.exp)
group <- c(rep("Deficient WM",12),rep("Healthy WM",12))

Condition <- c(rep("Non-Impulsive",6),rep("Impulsive",rep("Non-Impulsive",6))

data.summary <- data.frame(group,Condition,fig.data)

plot <- ggplot(data.summary,aes(x=group,y=fig.data,fill=Condition)) + 
  geom_Boxplot(outlier.colour="red",outlier.shape=8,outlier.size=4) + 
  scale_y_continuous(limits = c(40,100)) 

plot+labs(x="",y="MNIST TestSet Accuracy (%)\n")+
  theme_classic() +
  scale_fill_manual(values=c('#999999','#E69F00'))

谢谢你!

解决方法

尝试对数刻度。它将使它看起来更加接近,如下所示。

scale_y_continuous(limits = c(40,100),trans = "log10")

output

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。