2
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 轴标签使用 '%' 后缀?

4

2 回答 2

2

我们可以在将 设置为 'n'axis后使用参数yaxtbarplot

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在ieaxis中指定par(las = 1)

axis(2, at = seq(0, 0.6, by = 0.1), labels = paste0(seq(0, 0.6, by = 0.1), "%"), las = 1)

在此处输入图像描述

于 2017-01-28T20:28:37.890 回答
2

在@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 = " ")

在此处输入图像描述

于 2017-01-29T01:29:26.430 回答