Change outline and fill colors of histogram with qplot

时光毁灭记忆、已成空白 提交于 2019-12-10 14:37:00

问题


I have two histograms in one window (using facet) and I would like control over the color of the outline and the fill. I've tried looking up color scales, aes(), + color, + fill, including color and fill in qplot, all resulting in expected plots!

My code can be found below. (Note: mussel2 has two columns concentration (a list of numbers) and waterbody (listed or reference). I can provide the data if necessary.

I understand this is an elementary question, so I do appreciate your time.

qplot(data=mussel2,
    x = Concentration,
    xlim = x_lim, 
    ylim = y_lim, 
    xlab = expression(paste("Concentrations of DDE (", mu, "g/g)")), 
    ylab = "Frequency",
    binwidth = 1.5)+ 
    theme(legend.position="none")+
    facet_grid(Waterbody~.)

回答1:


If you want to keep the qplot format, try the following:

library(ggplot2)

qplot(diamonds$carat, 
      xlab="Carat", 
      geom="histogram", 
      ylab="Count", 
      binwidth=0.25, 
      fill=I("grey"), 
      col=I("black"))




回答2:


Use ggplot if you want to tweak things. I left out some of your options, but you can probably work out how to put them in.

ggplot(data = mussel2, aes(x = Concentration)) +
    geom_bar(binwidth = 1.5, fill = "firebrick4", color = "dodgerblue2") +
    scale_x_continuous(limits = x_lim) + 
    labs(y = "Frequency") +
    facet_wrap(~ Waterbody)


来源:https://stackoverflow.com/questions/18882206/change-outline-and-fill-colors-of-histogram-with-qplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!