I am plotting values from multiple data sets in the same plot under a stacked bars representation using the barplot() function in R and I have noticed that the legend is not displayed if for a certain plot I have data only from one data set. Having two or more categories (i.e., data sets) raises no problem and the legend is displayed correctly. Any idea if it is possible to force it to be displayed even for only one category ? Or I have to add a dummy category if for that plot I have data available from only one data set. Thank you.
EDIT : Here is how I call the bar plot:
barplot(bars, col = color_map[available_data], legend.text = T,
args.legend(bty = 'n'), ylim = my_computed_ylim,
xlim = my_computed_xlim, xlab = "X label", ylab = "Y label")
a = rep(5,25)
b = rep(10,25)
bars = rbind(a,b)
barplot(bars, col = seq(1,nrow(bars), by = 1), legend.text = T,
args.legend = c(bty = 'n')) bars = bars[-1,] barplot(bars,
col = 2, legend.text = T, args.legend = c(bty = 'n'))