Tah*_*sha 14 graphics r tikz ggplot2
嗨,我真的用Google搜索了很多,没有任何快乐.如果网站存在,很乐意获得对网站的引用.我很难理解Hadley关于极坐标的文档,我知道馅饼/甜甜圈图表本质上是邪恶的.
那就是说,我要做的是
为什么?我正在寻找财务信息.第一个环是成本(分解),第二个环是总收入.然后,我们的想法是+ facet=period在每个审核期间添加,以显示收入和支出以及两者的增长趋势.
任何想法都将非常感激
注意:如果尝试使用MWE,则完全随意
donut_data=iris[,2:4]
revenue_data=iris[,1]
facet=iris$Species
Run Code Online (Sandbox Code Playgroud)
这与我正在尝试做的类似..谢谢
bde*_*est 37
我对你的问题没有完整的答案,但我可以提供一些代码,可以帮助你开始使用环形图ggplot2.
library(ggplot2)
# Create test data.
dat = data.frame(count=c(10, 60, 30), category=c("A", "B", "C"))
# Add addition columns, needed for drawing with geom_rect.
dat$fraction = dat$count / sum(dat$count)
dat = dat[order(dat$fraction), ]
dat$ymax = cumsum(dat$fraction)
dat$ymin = c(0, head(dat$ymax, n=-1))
p1 = ggplot(dat, aes(fill=category, ymax=ymax, ymin=ymin, xmax=4, xmin=3)) +
geom_rect() +
coord_polar(theta="y") +
xlim(c(0, 4)) +
labs(title="Basic ring plot")
p2 = ggplot(dat, aes(fill=category, ymax=ymax, ymin=ymin, xmax=4, xmin=3)) +
geom_rect(colour="grey30") +
coord_polar(theta="y") +
xlim(c(0, 4)) +
theme_bw() +
theme(panel.grid=element_blank()) +
theme(axis.text=element_blank()) +
theme(axis.ticks=element_blank()) +
labs(title="Customized ring plot")
library(gridExtra)
png("ring_plots_1.png", height=4, width=8, units="in", res=120)
grid.arrange(p1, p2, nrow=1)
dev.off()
Run Code Online (Sandbox Code Playgroud)

思考:
iris数据集中的一些列(一个好的开始),但我无法看到如何使用该数据来制作环形图.例如,您链接的环形图显示了几个类别的比例,但既不是iris[, 2:4]也不iris[, 1]是分类.geom_rect(data=dat2, xmax=3, xmin=2, aes(ymax=ymax, ymin=ymin))period,则可以facet_wrap(~ period)用于facetting.ggplot2最容易使用,您需要"长形式"的数据; melt()从reshape2包中可能对转换数据很有用.ggplot(dat, aes(x=category, y=count, fill=category)) +
geom_bar(stat="identity")| 归档时间: |
|
| 查看次数: |
24503 次 |
| 最近记录: |