Colours in Boxplot

boxplot(R_KickPass, data=R_KickPass, main = "Median & IQR for Male and Female Kick Pass", ylab = "Dominant Limb Use")

Is the existing code and works. However, I want a different colour for four box plots on the same pane. Data has been imported from Excel. Boxplot One is called "Male Right Kick Pass", Two is "Male Left Kick Pass", Three is "Female Right Kick Pass" and four is "Female Left Kick Pass". The colours I want are Blue, lighter blue, Pink, lighter pink....the colours themselves aren't important obviously, just knowing how i go about this. If anyone could help I'd be very grateful.

# Define custom colors for each box
colors <- c("blue", "lightblue", "pink", "lightpink")

# Create the boxplot with custom colors
boxplot(Value ~ Group, data = data, main = "Median & IQR for Kick Pass",
        ylab = "Dominant Limb Use", col = colors)

But ggplot2 you could make this in better way:

install.packages('ggplot2')
library(ggplot2)

# Define custom colors for each box
colors <- c("blue", "lightblue", "pink", "lightpink")

# Create the boxplot using ggplot2
ggplot(data, aes(x = Group, y = Value, fill = Group)) +
  geom_boxplot() +
  labs(
    title = "Median & IQR for Kick Pass",
    y = "Dominant Limb Use"
  ) +
  scale_fill_manual(values = colors)

You are an absolute legend - first one worked perfectly! thank you

This topic was automatically closed 42 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.