r - 在 ggplot2 中编辑条形图
问题描述
我创建了一个条形图,我想对布局进行一些更改。我已经尝试了几件事,但我想做以下事情:
- 将 Y 轴间隔从 0 更改为 50%
- 使表示条形内百分比的字母的大小变小
- 删除灰色背景并将其更改为白色
该图可以在这里找到:在此处输入图像描述
我提供的代码是:
beoordeling <- ggplot(data=etadam, aes(x = beoordeling)) +
geom_bar(aes(y = (..count..)/sum(..count..)), colour = "black", width = 0.6, fill = '#ffd308') +
geom_text(aes(y = ((..count..)/sum(..count..)), label = scales::percent((..count..)/sum(..count..))), stat = "count", vjust = -0,2) +
scale_y_continuous(labels = percent) +
scale_x_continuous(breaks = seq(0, 10, by = 1)) +
labs(x = NULL, y = 'percentage', title = 'Welk cijfer geven jullie de examentraining?', subtitle = 'N = 400 | Alle trainingen', caption = 'Leren voor de Toekomst©')
解决方案
这应该做你想要的:
beoordeling <- ggplot(data=etadam, aes(x = beoordeling)) +
theme_minimal() +
geom_bar(aes(y = (..count..)/sum(..count..)), colour = "black", width = 0.6, fill = '#ffd308') +
geom_text(aes(y = ((..count..)/sum(..count..)), label = scales::percent((..count..)/sum(..count..))), stat = "count", vjust = -0,2, size = 2) +
scale_y_continuous(limits=c(0.5), expand = c(0,0),labels = percent) +
scale_x_continuous(breaks = seq(0, 10, by = 1)) +
labs(x = NULL, y = 'percentage', title = 'Welk cijfer geven jullie de examentraining?', subtitle = 'N = 400 | Alle trainingen', caption = 'Leren voor de Toekomst©')
添加
limits = c(0,0.5)
,如果你愿意expand = c(0,0)
的话scale_y_continuous()
。改变。
size
_geom_text()
我现在设置为 2使用或。
theme_minimal()
_ 查看ggplot 主题theme_classic()
theme_light()
推荐阅读
- ruby - 模块中的共享 minitest 测试使用类来描述上下文
- numpy - 如何让 stats.multivariate_normal.rvs 返回一个数组而不是标量?
- javascript - 如何修复错误:在 Windows 10 中生成 npm ENOENT?
- java - 在非静态方法中调用没有类实例的非静态方法
- ms-access - MS Access 启动时隐藏按钮
- c++ - boost::asio 使用 post() 时不调用处理程序,直接调用函数时有效(io_context 有效)
- node.js - 另一条路线中未定义的快速会话
- java - 如何使用 Spring CrudRepository 忽略表上的关系
- python - 在 django 中使用 for 循环遍历另一个 url
- json - 请问这个 JSON 文件有什么问题?