BoxPlot Adding Mean and Median Values

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

BoxPlot Adding Mean and Median Values

Jayaganesh
Dear Team - I would like to get your help on adding the values of mean and median of RTF as mentioned in the below snapshot. 

Please guide me out. Thanks for your help in advance.




______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: BoxPlot Adding Mean and Median Values

David Carlson
Your snapshot did not make it to the list. Only a few types of plots are accepted, e.g. .png. But we don't need a picture as much as we need a copy of your code with enough of your data to reproduce what you are trying to do. Use dput(head(x, 15)) to print out 15 lines of your data and include all of the R code you are using.

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-----Original Message-----
From: R-help <[hidden email]> On Behalf Of Jayaganesh Anbuganapathy
Sent: Tuesday, May 8, 2018 11:10 PM
To: [hidden email]
Subject: [R] BoxPlot Adding Mean and Median Values

Dear Team - I would like to get your help on adding the values of mean and median of RTF as mentioned in the below snapshot. 

Please guide me out. Thanks for your help in advance.




______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: BoxPlot Adding Mean and Median Values

Jayaganesh
In reply to this post by Jayaganesh
Hello Dave

Here is the code I have tried.

getwd()
setwd("D:/BAP Session/Nuance")
getwd()
AmbientTr <- read.csv("AmbientBatchbox.csv", stringsAsFactors = TRUE)

str(AmbientTr)
summary(AmbientTr)

install.packages("ggplot2")
library(ggplot2)

boxplot(RTF~Batch,data=AmbientTr, ylim = c(0,30), main="RTF By Batch",
xlab="Batch", ylab="RTF", col ="blue")

As I mentioned below, would like to add the data labels into each box of mean value
Can you help on this what needs to be added in this code to show the data labels.




On May 09, 2018, at 08:10 PM, David L Carlson <[hidden email]> wrote:

Your snapshot did not make it to the list. Only a few types of plots are accepted, e.g. .png. But we don't need a picture as much as we need a copy of your code with enough of your data to reproduce what you are trying to do. Use dput(head(x, 15)) to print out 15 lines of your data and include all of the R code you are using.

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-----Original Message-----
From: R-help <[hidden email]> On Behalf Of Jayaganesh Anbuganapathy
Sent: Tuesday, May 8, 2018 11:10 PM
To: [hidden email]
Subject: [R] BoxPlot Adding Mean and Median Values

Dear Team - I would like to get your help on adding the values of mean and median of RTF as mentioned in the below snapshot. 

Please guide me out. Thanks for your help in advance.




______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: BoxPlot Adding Mean and Median Values

S Ellison-2
> Here is the code I have tried.
The code has to work to be useful.
including the data read - which, because it is on your D: drive, clearly can't be read..

But here are some comments and some base graphics code that should get you started;

> As I mentioned below, would like to add the data labels into each box of mean
> value
        #You'll need to calculate the mean values separately. A standard boxplot doesn't include them

> AmbientTr <- read.csv("AmbientBatchbox.csv", stringsAsFactors = TRUE)
        #Not possible

> str(AmbientTr)
> summary(AmbientTr)
        #Not possible
> install.packages("ggplot2")
        #Don;t need to do this every time
> library(ggplot2)
        #And you don’t need it at all: you are using 'boxplot', which is in base graphics

> boxplot(RTF~Batch,data=AmbientTr, ylim = c(0,30), main="RTF By Batch",
> xlab="Batch", ylab="RTF", col ="blue")
        #Try assigning the result of boxplot to a variable, such as
bw.data <-  boxplot(RTF~Batch,data=AmbientTr, ylim = c(0,30), main="RTF By Batch",
         xlab="Batch", ylab="RTF", col ="blue")

#Then you csan use that data to place labels etc. because boxplot returns the stats for the boxes, and the locations
#are (by default) at 1:length()bw.data$names.

#For example, after the above plot:
with(bw.data, text(1:length(names), stats[3,], names, pos=1) #labels just below the medians

#And for placing means on the plot:
RTFmeans <- with(AmbientTr, tapply(RTF, batch, mean))
points(1:length(RTFmeans), RTFmeans, pch=19)
text(1:length(RTFmeans), RTFmeans, paste(round(RTFmeans,0)), pos=3) #labels just above the points

#... or something like that.

For a ggplot equivalent, you could try the ggplot mailing list; Google it to find it.

S Ellison


*******************************************************************
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If
you have received this message in error, please notify the sender
immediately via +44(0)20 8943 7000 or notify [hidden email]
and delete this message and any copies from your computer and network.
LGC Limited. Registered in England 2991879.
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
______________________________________________
[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.