A long time ago I didn't use base R to make graphs, but today I wanted to make a boxplot.
set.seed(2021)
x<-c(sample(1:100,50,T),sample(200:400,7,T))
# El gráfico.
boxplot(x, col = "orange", frame.plot=F)
legend("topright",legend = paste0("% de Outliers = ",
round(length(boxplot(x)$out)*100/length(x),2),"%"),
cex=.8,inset=.02, fill = "orange")
But curiously the result is that the box of the boxplot is gray. Apparently when applying the legend the color was changed from "orange" to "gray". I don't know why this happens. Before placing the legend did not imply that the color of the box changed.
What could be the cause, is it an R update? Is it a problem with my R installation? In the event that it is an update, how can I make the color of the box remain "orange".
Psdta: I use R 4.1
The problem is that every time you invoke
boxplot()
the collateral effect is triggered, that is, the graph, and in your code you are doing it twice, the first time with the appropriate color:And the second, this time without color, when you recover the "outliers":
What you can do eventually is save the graph in a variable so that from this you can obtain the data for the legend: