由于数据输入,我有一个稀疏的图
数据输入
dframe <- structure(list(value = c(1L, 2L, 3L, 4L, 5L, 8L, 6L, 7L,
10L, 9L, 14L, 15L, 20L, 22L, 24L), level= c(1009L, 103L, 43L,
7L, 5L, 4L, 3L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 1L)), class = "data.frame", row.names = c(NA,
-15L))以及剧情:
library(ggplot2)
p <- ggplot(data=dframe, mapping = aes(x=value, y=level)) +
geom_col(color = '#032838', fill = 'steelblue', size = 1) +
geom_text(aes(label = level), vjust = -0.4, size = 4, position = position_dodge(0.9))在x轴上频率为30之后,有没有不会如此稀疏的替代图?
发布于 2021-05-12 22:18:15
这里有一个假设:你可以放大图中数据更稀疏的部分。使用ggforce的示例
library(ggforce)
#transform your data to be plotted by geom_histogram (or geom_density)
df <- data.frame(value=rep(dframe$value,dframe$level))
ggplot() +
geom_histogram(aes(x=value),dplyr::mutate(df, z = F),bins = 25,color = '#032838', fill = 'steelblue') +
geom_histogram(aes(x=value),dplyr::mutate(df, z = T),bins =50,color = '#032838', fill = 'steelblue') +
facet_zoom(xlim = c(5, 25),ylim=c(0,10), horizontal = F,zoom.data = z,zoom.size=0.5)+
theme(zoom.y = element_blank(), validate = FALSE)这为您提供了:

您可以尝试使用bins参数来找到适合您的完美解决方案。
注意:我删除了geom_text部件,因为您没有提供Users变量
发布于 2021-05-12 22:23:32
为什么不直接取level数据的对数呢?在这种情况下,这将是标准的做法。考虑一下:
p <- ggplot(data=dframe, mapping = aes(x=value, y=log(level))) +
geom_col(color = '#032838', fill = 'steelblue', size = 1)

https://stackoverflow.com/questions/67504471
复制相似问题