x轴上的因素太多 [英] Too many factors on x axis

查看:145
本文介绍了x轴上的因素太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设因子变量是有序的,处理情节中太多因素的最佳方法是什么?默认看起来不太好:

  ggplot(data.frame(x = factor(trunc(runif(10000,0, 100)),ordered = T)),aes(x = x))+ 
geom_histogram()

解决方案

  ggplot(data.frame(x = factor(trunc(runif) (10000,0,100)),ordered = T)),aes(x = x))+ 
theme(axis.text.x = element_text(angle = 90,hjust = 1))+
)geom_histogram()

flip < - ggplot(data.frame(x = factor(trunc(runif(10000,0,100)),ordered = T)),aes(x = x) )+
theme(axis.text.x = element_text(angle = 90,hjust = 1))+
geom_histogram()

如果您的口味过于密集,您可以设置手动分页。在这种情况下,我使用五个。

 修剪<  -  ggplot(data.frame(x = factor(trunc(runif 10000),有序= T)),aes(x = x))+ 
主题(axis.text.x = element_text(angle = 90,hjust = 1))+
scale_x_discrete(breaks = seq(0,100,by = 5))+
geom_histogram()

library(gridExtra)
grid.arrange(翻转,修剪)


What's the best way to deal with too many factors in a plot, assuming that the factor variable is ordered? The default doesn't look nice:

ggplot(data.frame(x=factor(trunc(runif(10000, 0, 100)), ordered=T)), aes(x=x)) +
  geom_histogram()

解决方案

You can flip the values.

ggplot(data.frame(x=factor(trunc(runif(10000, 0, 100)), ordered=T)), aes(x=x)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  geom_histogram()

flip <- ggplot(data.frame(x=factor(trunc(runif(10000, 0, 100)), ordered=T)), aes(x=x)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  geom_histogram()

If it's still too dense for your taste, you can set manual breaks. In this case, I use five.

prune <- ggplot(data.frame(x=factor(trunc(runif(10000, 0, 100)), ordered=T)), aes(x=x)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  scale_x_discrete(breaks = seq(0, 100, by = 5)) +
  geom_histogram()

library(gridExtra)
grid.arrange(flip, prune)

这篇关于x轴上的因素太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆