gpt4 book ai didi

R barplot - 如何添加 y 轴 '%' 后缀?

转载 作者:行者123 更新时间:2023-12-05 02:19:38 25 4
gpt4 key购买 nike

pdf("whatever.pdf", height=4,width=8)
B <- c(0,0.585,0.043,0.006,0.012,0.244,0.004,0.008,0.119,0.012,0.095)
barplot(B, names.arg = c("ce","de","en","es","fr","it","ja","nl","ru","sv","All"), las=1, ylim=c(0, 0.6))
dev.off()

y 轴以百分比表示,如何让 y 轴标签使用“%”后缀?

最佳答案

根据@Akrun 的回答,下面是使用 ggplot2

的答案
B <-  c(0, 0.585,0.043,0.006,0.012,0.244,0.004,0.008,0.119,0.012,0.095)
A <- c("ce","de","en","es","fr","it","ja","nl","ru","sv","All")
df <- as.data.frame(cbind(A, B))

df$B<-as.numeric(as.character(df$B))

ggplot(df, aes(x = A, y = B))+
geom_bar(stat= "identity")+
scale_y_continuous(breaks = seq(0, 0.6, by = 0.1),
labels = paste(seq(0, 0.6, by = 0.1), "%"))+
labs(x = "", y = " ")

enter image description here

关于R barplot - 如何添加 y 轴 '%' 后缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41914463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com