将颜色添加到百分比直方图R.

时间:2017-02-21 18:28:52

标签: r

我有一个数据集已经有我将使用的百分比内置,我只想在直方图中绘制它们。

数据集如下所示:

Drug    Percentage
Quinolone   44.4
Cephalosporins  33.3
Piperacillin/Tazobactam 18.5
Metronizadole   33.3
Vancomycin  11

生成直方图的代码如下所示:

library(ggplot2)
cbPalette6 <- c("#E69F00", "#009E73", "#F0E442", "#D55E00", "#CC79A7")
df <- read.table("reports.txt", stringsAsFactors = F, sep = '\t', header = T)
ggplot(df, aes(x=Drug, y=Percentage, colour=Drug, fill=Drug, group=Drug, binwidth=10)) +
    ggtitle("Previous semester antibiotic treatment") +
    theme_bw() +
    theme(axis.line = element_line(size=1, colour = "black"),
          panel.grid.major = element_line(colour = "#D2D2D2"),
          panel.grid.minor = element_blank(),
          panel.grid.major.x = element_blank(),
          panel.border = element_blank(), panel.background = element_blank(),
          plot.title = element_text(size = 14, family = "Tahoma", face = "bold", hjust=0.5),
          text=element_text(family="Tahoma"),
          axis.title.x = element_text(size=15),
          axis.text.x = element_blank(),
          axis.ticks.x = element_blank(),
          axis.title.y = element_text(size=15),
          axis.text.y = element_text(colour="black", size = 15)) +
    geom_bar(stat="identity") + 
    geom_text(aes(y=Percentage + 1), size = 6, color = 'black', label = df$Percentage) +
    scale_colour_manual(values=cbPalette6)

如何在柱状图中添加custom coloring?并调整bin大小一点? 因为ggplot正在使用它的自定义色标,我不喜欢......

0 个答案:

没有答案