[R] adding a data point on a boxplot
David Winsemius
dwinsemius at comcast.net
Mon Jul 25 18:16:05 CEST 2016
> On Jul 25, 2016, at 3:20 AM, Pierre Micallef <micallefpierre at hotmail.com> wrote:
>
> Hi
>
>
> Please could somebody offer some assistance with the following problem?
>
> I am trying to use the boxplot function. As standard it displays (min, lower Q, median, Upper Q and Max). For each dotplot I would also like to add the current/most recent value from my data series as a data point. The goal being to graphically show where current values are compared to the above standard statistics.
>
> I have removed the date columns from the data but it should be in descending order i.e. the last data point in each series should be the current value.
>
> Happy for someone to amend the whole code if there is a smarter way of doing it.
>
> Thanks for any help you can give with this.
>
> See code below:
>
> blpConnect()
>
>
> data<-data.frame(LargeValue=bdh("DJUSVL Index", c("PX_LAST"), start.date=Sys.Date()-252*5),
> LargeGrowth=bdh("DJUSGL Index", c("PX_LAST"), start.date=Sys.Date()-252*5))
> data <- data[,!names(data) %in% c("LargeValue.date","LargeGrowth.date")]
> boxplot(data, las = 2, names = c("Large Value"," Large Growth"), col = c("red","royalblue2"),main=toupper("Box Plot Value vs Growth"), Xlab="Index Level", range = 0, horizontal=TRUE)
>
>
This should be very easy. (I'm not reviewing your code since it is obviously not reproducible yet. Presumably you would want to use tail( vectname, 1) to get the last point.)
To plot a large red "point" (actually a circle) at 0 in the first "column" of the first example on the ?boxplot page, you would issue:
points(1, 0, cex=5, col="red")
--
David.
>
> Thanks
> Pierre
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list