如何从 geom_tile 制作甜甜圈图
How to make from geom_tile a donut graph
我想根据分类数据制作一个简单的圆形甜甜圈注释图。因此,我先做一个简单的geom_tile
plot,然后再添加coord_polar()
函数。但是,我似乎无法控制ylim来制作甜甜圈图,因为它会产生以下错误:
Error: Discrete value supplied to continuous scale.
现在我被这个数字困住了:
重现剧情,帮我解惑:
examp = data.frame(rep(c("A","B"),each=12),
rep(c("C","D"),times=12),
rep(c("E","F","G"),each=8),
rep(c("E","H","G"),each=8),
1:24)
colnames(examp) = c("col1", "col2", "col3","col4","person")
examp$person = paste0("per.",examp$person)
examp2 <- melt(examp, id.var = 'person')
ggplot(examp2, aes(x=person,y=variable)) +
geom_tile(aes(fill = value), colour = "white")+
scale_y_discrete(breaks=y_breaks, labels=y_labels) +
coord_polar()+
theme(panel.background=element_blank(),
axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.x=element_blank(),
axis.ticks=element_blank(),
axis.text.y=element_text(size=5))
在 scale_y_discrete()
范围内指定扩展量对您有用吗?
ggplot(examp2, aes(x=person, y=variable)) +
geom_tile(aes(fill = value), colour = "white")+
scale_y_discrete(expand = expansion(mult = c(0.5, 0), add = 0)) + # change amount if needed
coord_polar()+
theme(panel.background=element_blank(),
axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.x=element_blank(),
axis.ticks=element_blank(),
axis.text.y=element_text(size=5))
(我跳过了休息/标签,因为你实际上并没有在问题中定义它们。)
我想根据分类数据制作一个简单的圆形甜甜圈注释图。因此,我先做一个简单的geom_tile
plot,然后再添加coord_polar()
函数。但是,我似乎无法控制ylim来制作甜甜圈图,因为它会产生以下错误:
Error: Discrete value supplied to continuous scale.
现在我被这个数字困住了:
重现剧情,帮我解惑:
examp = data.frame(rep(c("A","B"),each=12),
rep(c("C","D"),times=12),
rep(c("E","F","G"),each=8),
rep(c("E","H","G"),each=8),
1:24)
colnames(examp) = c("col1", "col2", "col3","col4","person")
examp$person = paste0("per.",examp$person)
examp2 <- melt(examp, id.var = 'person')
ggplot(examp2, aes(x=person,y=variable)) +
geom_tile(aes(fill = value), colour = "white")+
scale_y_discrete(breaks=y_breaks, labels=y_labels) +
coord_polar()+
theme(panel.background=element_blank(),
axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.x=element_blank(),
axis.ticks=element_blank(),
axis.text.y=element_text(size=5))
在 scale_y_discrete()
范围内指定扩展量对您有用吗?
ggplot(examp2, aes(x=person, y=variable)) +
geom_tile(aes(fill = value), colour = "white")+
scale_y_discrete(expand = expansion(mult = c(0.5, 0), add = 0)) + # change amount if needed
coord_polar()+
theme(panel.background=element_blank(),
axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.x=element_blank(),
axis.ticks=element_blank(),
axis.text.y=element_text(size=5))
(我跳过了休息/标签,因为你实际上并没有在问题中定义它们。)