[R] Σχετ: change colour in barplot

Maria Lathouri mlathouri at yahoo.gr
Mon Nov 20 13:09:34 CET 2017


Dear all, 
I am really sorry for this. I have attached the script and a .csv file with an example. 
Hope this will help.
Many thanks,Maria 

    Στις 11:53 π.μ. Δευτέρα, 20 Νοεμβρίου 2017, ο/η Duncan Murdoch <murdoch.duncan at gmail.com> έγραψε:
 

 On 20/11/2017 6:38 AM, Maria Lathouri via R-help wrote:
>  Dear all
> I know that it is a very simple question but it seems that I cannot change the colour in the bars.
> I have the following dataframe:
> A                  B                 C           D          E                    F                    G                0.0.24          152460         474       5.5        612000           59061000       1540313
> and here is the script:
> setwd("~/Desktop")
> emission<-read.csv("emission from land.csv")
> attach(emission)
> #define the formulas
> Emission_from_Land<-A*B*C*DEmission_from_Access_Road<-E*(F/1000000)*CEmissions_from_well<-(G/1000000)*E*C
> #combine my outputs into a new dataframe
> dat<-cbind(Emission_from_Land, Emission_from_Access_Road, Emissions_from_well_pad)
> #plot a barplot
> barplot(dat, ylab="Kg-CO2 Eq", ylim=c(0.0e+00, 2e+10), axisnames=FALSE, col=c("blue", "red", "orange"),
>          main ="Well Site Construction Emissions", legend.text=c("Land", "Access", "Well"),
>          args.legend = list(x="bottom", horiz="TRUE", bty="n", inset=c(-0.5, -0.25)))
> When I add the col= argument, the colour changes in the legend but not the actual bars in the plot. I don't know what I am doing wrong. I know that I am missing something but I cannot figure it out.
> I would very much appreciate for your help.

We don't have your data, so we can't reproduce that plot.  But when I do 
the following, I see three colours:

dat <- matrix(1:9, ncol=3)*0.5e9
par(mfrow=c(2,2))
barplot(dat, ylab="Kg-CO2 Eq", ylim=c(0.0e+00, 2e+10), axisnames=FALSE, 
col=c("blue", "red", "orange"),
          main ="Well Site Construction Emissions", 
legend.text=c("Land", "Access", "Well"),
          args.legend = list(x="bottom", horiz="TRUE", bty="n", 
inset=c(-0.5, -0.25)))

So you'll need to give us a reproducible example if you want help.

Duncan Murdoch


   


More information about the R-help mailing list