相关疑难解决方法(0)

在ggplot2中的条形图上舍入%标签

q1 <- qplot(factor(Q1), data=survey, geom="histogram", fill=factor(Q1), ylim=c(0,300))

options(digits=2)

q1 + geom_bar(colour="black") + 
stat_bin(aes(label=..count..), vjust=-2, geom="text", position="identity") +
stat_bin(geom="text", aes(label=paste(..count../sum(..count..)*100,"%"), vjust=-0.75)) +
labs(x="Question # 1:\n 0 = Didn't respond, 1 = Not at all familiar, 5 = Very familiar") +
opts(title="Histogram of Question # 1:\nHow familiar are you with the term 'Biobased Products'?", 
    legend.position = "none",
    plot.title = theme_text(size = 16, , vjust = 1, face = "bold"), 
    axis.title.x =theme_text(size=14), axis.text.x=theme_text(size=12),
    axis.title.y=theme_text(size=14, angle=90), axis.text.y=theme_text(size=12))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

正如你所看到的,我得到的数字超过了所需的数字,我希望选项(数字= 2)可以做到,但我猜不是.有任何想法吗?

r rounding bar-chart ggplot2

14
推荐指数
1
解决办法
8257
查看次数

ggplot2:如何将百分比标签添加到圆环图

我对R来说很新...所以请原谅我.我正在尝试使用ggplot2制作甜甜圈图.我修改了后期ggplot甜甜圈图表的代码, 但现在我无法在图表上添加百分比.这是我的尝试:

library(ggplot2)

blank_theme <- theme_minimal()+
  theme(
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    panel.border = element_blank(),
    panel.grid=element_blank(),
    axis.ticks = element_blank(),
    plot.title=element_text(size=14, face="bold")
  )



dat = data.frame(count=c(319, 442, 239), category=c("University", "High Scool", "Lower"))


dat$fraction = dat$count / sum(dat$count)

dat$ymax = cumsum(dat$fraction)
dat$ymin = c(0, head(dat$ymax, n=-1))

dat$category <- factor(dat$category, levels = c("University", "High Scool", "Lower"))


p1 = ggplot(dat, aes(fill=category, ymax=ymax, ymin=ymin, xmax=4, xmin=3)) +
  geom_rect(color='blue') +
  coord_polar(theta="y") +
  xlim(c(1, 4)) 



edu<-p1 + scale_fill_brewer("Education") + blank_theme +
  theme(axis.text.x=element_blank()) + theme(legend.position=c(.5, …
Run Code Online (Sandbox Code Playgroud)

r percentage ggplot2 donut-chart

7
推荐指数
1
解决办法
3675
查看次数

标签 统计

ggplot2 ×2

r ×2

bar-chart ×1

donut-chart ×1

percentage ×1

rounding ×1