【发布时间】:2022-01-13 01:08:19
【问题描述】:
在 R/ggplot2 中,当我使用geom_bar(stat='identity',position='fill') 时,
“销售”提示显示“0.80000”,如何将其更改为“80.0%”?
(我知道变异一个新变量使用scales::percent(sales),可以在geom_point工作)
library(tidyverse)
library(plotly)
test_data <- data.frame(category=c('A','B','A','B'),
sub_category=c('a1','b1','a2','b2'),
sales=c(1,2,4,5))
p <- test_data %>%
ggplot(aes(x=category,y=sales,
fill=sub_category))+
geom_bar(stat='identity',position='fill')
ggplotly(p)
【问题讨论】: