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. Many thanks,Maria [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
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 ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
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 <[hidden email]> έγραψε: 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 ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
On 20/11/2017 7:09 AM, Maria Lathouri wrote:
> Dear all, > > I am really sorry for this. I have attached the script and a .csv file > with an example. The problem is that you have dat as a matrix with only one row. barplot() applies the colours to the rows of dat; since you have only one row, everything ends up blue. You can fix this by creating dat as a vector using dat<-c(Emission_from_Land, Emission_from_Access_Road, Emissions_from_well_pad) or by using "beside = TRUE" in the arguments to barplot. These will give similar but slightly different results; I don't know which one is better for you, but I like the vector solution better. Duncan Murdoch > > Hope this will help. > > Many thanks, > Maria > > > Στις 11:53 π.μ. Δευτέρα, 20 Νοεμβρίου 2017, ο/η Duncan Murdoch > <[hidden email]> έγραψε: > > > 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 > > > ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Dear Duncan
Many thanks for this; actually the vector solution works much better. Best, Maria Στις 12:27 μ.μ. Δευτέρα, 20 Νοεμβρίου 2017, ο/η Duncan Murdoch <[hidden email]> έγραψε: On 20/11/2017 7:09 AM, Maria Lathouri wrote: > Dear all, > > I am really sorry for this. I have attached the script and a .csv file > with an example. The problem is that you have dat as a matrix with only one row. barplot() applies the colours to the rows of dat; since you have only one row, everything ends up blue. You can fix this by creating dat as a vector using dat<-c(Emission_from_Land, Emission_from_Access_Road, Emissions_from_well_pad) or by using "beside = TRUE" in the arguments to barplot. These will give similar but slightly different results; I don't know which one is better for you, but I like the vector solution better. Duncan Murdoch > > Hope this will help. > > Many thanks, > Maria > > > Στις 11:53 π.μ. Δευτέρα, 20 Νοεμβρίου 2017, ο/η Duncan Murdoch > <[hidden email]> έγραψε: > > > 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 > > > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by R help mailing list-2
Just so you know, your attachments were stripped on the mailing list both times. It was your direct cc to Duncan that allowed him to see your attachments. Please avoid using attachments in the future, and if you must anyway then read the Posting Guide about which MIME type attachments are allowed so others can contribute to the discussion and benefit from the exchange you do have. (You can verify how your email/attachments came through by reading it on the mailing list archives.)
-- Sent from my phone. Please excuse my brevity. On November 20, 2017 4:09:34 AM PST, Maria Lathouri via R-help <[hidden email]> wrote: >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 ><[hidden email]> έγραψε: > > > 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 > > > >______________________________________________ >[hidden email] mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble - Free Resume Builder | Edit this page |