R 装箱数据的频率图

R 装箱数据的频率图,r,ggplot2,R,Ggplot2,我已经将数据分为不同的大小,并希望在给定的花瓣长度范围内为每个物种绘制一个分面频率图(每个大小的分面直方图,如附图所示) 我该怎么做?我在设置x轴时遇到问题,因为我希望x轴连续并将其分块打印。这里是一种使用facet\u wrap的方法。我们可以使用str\u replace\u allfromstringr来改善轴标签的外观 library(ggplot2) library(stringr) ggplot(df, aes(x = pl, y = Freq, fill = spe)) +

我已经将数据分为不同的大小,并希望在给定的花瓣长度范围内为每个物种绘制一个分面频率图(每个大小的分面直方图,如附图所示)


我该怎么做?我在设置x轴时遇到问题,因为我希望x轴连续并将其分块打印。

这里是一种使用
facet\u wrap
的方法。我们可以使用
str\u replace\u all
from
stringr
来改善轴标签的外观

library(ggplot2)
library(stringr)
ggplot(df, aes(x = pl, y = Freq, fill = spe)) +
  geom_bar(stat = "identity") +
  scale_x_discrete(labels = function(x)
    str_replace_all(x, regex(c("[\\(\\[]" = "", "," = " - ", "\\]" = "")))) + 
  facet_wrap(.~spe, ncol = 1) + 
  theme(axis.text.x=element_text(angle = 45, hjust = 1))

另一种方法是使用
geom\u直方图

ggplot(df1, aes(x = Petal.Length, fill = Species)) + 
  geom_histogram(color = "white", bins = 20) + 
  facet_wrap(.~Species, ncol = 1)

有没有办法使x轴连续且不分格?如果我遗漏了什么,很抱歉,但为什么不直接使用
geom_直方图
?这样你就有了更多的控制权。是的,这样你就不用再乱动x轴标签了。看看我的编辑。
ggplot(df1, aes(x = Petal.Length, fill = Species)) + 
  geom_histogram(color = "white", bins = 20) + 
  facet_wrap(.~Species, ncol = 1)