Skip to content
Prev 377980 / 398502 Next

Plotting rgb proportions in R

Hi Tasha,
Using the original sample you sent:

rgb_prop<-read.table(text="Red Green Blue pct
249 158 37 56.311
249 158 68 4.319
249 158 98 0.058
249 128 7 13.965
249 128 37 12.87
188 128 37 0.029
249 128 68 0.161
188 128 68 0.015
188 98 7 0.029
219 128 7 2.773
219 128 37 2.583
188 98 68 0.058
219 128 68 0.525
249 188 37 0.876
249 188 68 1.08
219 98 7 0.482
249 188 98 0.015
249 158 7 3.852",header=TRUE)
rgb_prop$Red<-rgb_prop$Red/255
rgb_prop$Green<-rgb_prop$Green/255
rgb_prop$Blue<-rgb_prop$Blue/255
# the matrix format forces the stacked bar display
barplot(matrix(rgb_prop$pct,ncol=1),
 col=rgb(rgb_prop[,c("Red","Green","Blue")]),beside=FALSE)

Of course you can add more stacks by increasing the number of columns in
the "x" matrix.

Jim
On Thu, Jan 3, 2019 at 3:33 AM Tasha O'Hara <tasha.eileen at gmail.com> wrote: