Color specific ranges of boxplots

Hello community,

I created the following boxlopt:

boxplot(LCZ_fm[,'SVF_mean'] ~ LCZ_fm[,'LCZ'],
        main='Sky View Factor pro LCZ-Klasse',
        ylab='SVF', xlab='LCZ', 
        na.action = NULL
        )

grafik

Now I would like to color specific ranges for each boxplot (like I drafted in green), showing the 'optimal range' of values for each group ('LCZ', on the x axis) according to literature, to illustrate how my data deviates from these theoretical values.

Any suggestions? Could I maybe use some sort of faceting technique from ggplot2?

Bonus question: My goal is to regroup my data, so that the values fit better into the theoretical ranges. Meaning, some data points are going to be assigned to a new group (LCZ). Does someone have an idea how I could compare the before and after data using statistics to quantify how much more accurate the grouping is, i.e. if the deviation from theoretical value ranges has decreased overall?

Thanky you!

Here is one approach to adding colored boxes to a box plot.

#Invent data
DF <- data.frame(LCZ = rep(1:3, each = 30),
                 Value = c(rnorm(30), rnorm(30, 1, 1), rnorm(30,4, 1)))
DF_Expect <- data.frame(LCZ = 1:3, Value = c(0.3, 1.2, 3.3), Height = c(1.3, 0.8, 1.7))

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.0.5
ggplot(DF, aes(LCZ, Value, group = LCZ)) + geom_boxplot() +
  geom_tile(aes(x = LCZ, y = Value, height = Height, width = 0.7), 
            fill = "green", alpha = 0.5, data = DF_Expect)

Created on 2021-07-16 by the reprex package (v0.3.0)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.