简体   繁体   English

我可以使用什么 function 来限制 geom_bar plot 中的 y 轴?

[英]What function can I use to limit my y-axis in a geom_bar plot?

I am new to R and making a very simple histogram, however the range of my y-axis is too large and greatly limits visibility of the graph.我是 R 的新手并制作了一个非常简单的直方图,但是我的 y 轴范围太大并且极大地限制了图表的可见性。 I have tried using ylim however I get the error "Error in discrete_scale(c("x", "xmin", "xmax", "xend"), "position_d", : unused argument (ylim = c(0, 75))"我曾尝试使用 ylim,但出现错误“discrete_scale 中的错误(c(“x”、“xmin”、“xmax”、“xend”)、“position_d”、:未使用的参数(ylim = c(0、75) )"

Here is the code used to make the histogram:这是用于制作直方图的代码:

recipes %>%
mutate(ingredient = fct_infreq(ingredient)) %>%
ggplot(aes(x = ingredient)) +
geom_bar() +
scale_x_discrete(labels = NULL)

Any help and suggestions would be greatly appreciated.任何帮助和建议将不胜感激。

you seem to have a wrong sintax in ylim.您似乎在 ylim 中有错误的语法。 Try with:尝试:

recipes %>%
mutate(ingredient = fct_infreq(ingredient)) %>%
ggplot(aes(x = ingredient)) +
geom_bar() +
scale_x_discrete(labels = NULL) +
ylim(0, 75)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM