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轴标签使用&#39;%&#39;后缀?
答案 0 :(得分:1)
我们可以在axis
yaxt
到'n'之后使用barplot
参数
par(las = 1)
barplot(B, names.arg = c("ce","de","en","es","fr","it","ja","nl","ru","sv","All"),
las=1, ylim=c(0, 0.6), yaxt="n")
axis(2, at = seq(0, 0.6, by = 0.1), labels = paste0(seq(0, 0.6, by = 0.1), "%"))
或者我们可以在las
而不是axis
中指定par(las = 1)
,即
axis(2, at = seq(0, 0.6, by = 0.1), labels = paste0(seq(0, 0.6, by = 0.1), "%"), las = 1)
答案 1 :(得分:1)
按照@ 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 = " ")