控制由ggplot2中的因子变量生成的饼图中的刻度和奇数文字 [英] Controlling ticks and odd text in a pie chart generated from a factor variable in ggplot2
本文介绍了控制由ggplot2中的因子变量生成的饼图中的刻度和奇数文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码生成一个简单的饼图:
I'm generating a simple pie chart with use of the code below:
data(mtcars)
mtcars$fac_var <- as.factor(mtcars$cyl)
require(ggplot2); require(ggthemes)
# Chart
pie_test <- ggplot(mtcars, aes(x = factor(1), fill = fac_var)) +
geom_bar(width = 1) +
coord_polar(theta = "y") +
ggtitle("Title") +
theme_pander() +
scale_fill_tableau(name = "Something") +
theme(axis.title = element_blank())
代码产生以下图表:
我有兴趣对上面的图表进行两个较小的修改:
I'm interested in introducing two minor modifications to the chart above:
- 我要删除左侧中可见的图形 1 (在下图中以红色突出显示).
- 我想使通向数字的线条更清晰地表达(在下图中以黑色突出显示).
- I would like to remove the figure 1 visible on the left (highlighted in red in the picture below).
- I would like to make the lines leading to to the figures more strongly pronounced (highlighted in black in the picture below).
所需的更改:
推荐答案
1.)摆脱"1-" 将主题编辑为:
1.) To get rid of the "1-" edit your theme to:
theme(axis.title = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank())
2.)要更改行,请将主题编辑为:
2.) To change the lines edit your theme to:
theme(axis.title = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y=element_blank(),
panel.grid.major.y = element_line(size = 1, color="black", linetype = "solid"))
不是完美的解决方案,而是一种改进.饼图并不是传达数据的最佳选择.您可能要考虑条形图.如果您想进一步了解ggplot2饼图,请查看这篇文章.
Not a perfect solution but an improvement. Pie charts are not the best for conveying data. You may want to consider a bar chart. If you want more help with ggplot2 pie charts check out this post.
这篇关于控制由ggplot2中的因子变量生成的饼图中的刻度和奇数文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文