简体   繁体   中英

How can I visualize specific data points in a boxplot in R?

I have some monthly time-series data and I need to create a boxplot on this data using R. Until here, no problem of course. Then, additionally to the median, 1st quartile and 3rd quartile, I also need to visualize in the graph specific data points coming from the time-series, namely the observations at 3 years, 1 year and 3 months in the past. I looked online but I can't seem to find any command for this. Is there a way I can add these observation to the boxplot?

You can use, for example, the text function:

set.seed(123)
x <- rnorm(100, 5, 10)

If you want to display the mean value:

boxplot(x)
text(1, mean(x), "x", col = "red")

Additionally or alternatively, you can use the function points :

points(IQR(x), col = "blue", pch = 8)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM