[R] multiple colour to symbols using brkdn.plot()

Luigi Marongiu marongiu.luigi at gmail.com
Thu May 22 14:43:23 CEST 2014


 Dear all,
I have been plotting response variable (defined as "y" in the example
below) from 4 groups (defined as "z" variable ) under 5 conditions
(defined by the "x" variable). The formula used is: y ~ z+x.
I can differentiate the different z value using a call pch=c(symbol 1,
symbol 2, ...) but it would be even better to have different colours
for each of these symbols.
In analogy to the pch=c(symbol 1, symbol 2, ...) i have tired to
provide a bg(colour 1, colour 2, ...) but this give the colour to the
x variables rather than the z ones.
How can I give the colour to the z variables?

best regards,
Luigi


# code:
my.data<-structure(list(
  row = 1:60,
  x = c(
0, 0, 0, 1, 1, 1, 2, 2, 2,
3, 3, 3, 4, 4, 4, 0, 0, 0,
1, 1, 1, 2, 2, 2, 3, 3, 3,
4, 4, 4, 0, 0, 0, 1, 1, 1,
2, 2, 2, 3, 3, 3, 4, 4, 4,
3, 3, 3, 0, 0, 0, 1, 1, 1,
2, 2, 2, 3, 3, 3, 4, 4, 4),
  y = c(
2073.928223, 2131.830067, 2131.830067, 0.143912883,
2191.348468, 2073.928223, 2117.20479, 2017.59903, 1896.388977,
1976.358448, 2003.757427, 1883.378928, 2283.756186,
2363.732429, 2315.416732, 2206.485917, 2191.348468,
2176.314869, 1990.010783, 2059.700178, 1976.358448,
617.4528799, 613.2168858, 617.4528799, 1686.950197,
1819.655315, 1832.225173, 1480.122531, 1298.652866,
1212.260417, 495.3736815, 505.7106218, 538.0337432,
383.9842946, 365.919416, 330.0195927, 505.7106218,
541.7503854, 498.7956356, 512.7214729, 584.3675585,
564.5956413, 604.8318804, 604.8318804, 592.4688595,
1272.107849, 1298.652866, 1298.652866, 1935.96084,
2088.254554, 1962.799773, 4452.994159, 4422.444691,
4128.243033, 312.3359691, 316.6659968, 332.2993098,
1500.642011, 1531.95584, 1430.042989),
  z = c(
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3)),
 row.names = c(NA, -60L),  class = "data.frame")
attach(my.data)
### *** PLOT DATA *** ###
# open library
 library(plotrix)
par(mfrow = c(1, 2))
brkdn.plot(
  y ~ z+x,data=my.data, mct="mean", md="sd",
  stagger=NA, dispbar=TRUE,
  type="p", pch=c(0, 1, 2, 5),
  main="z indicated by symbol ",
  xlab=expression(bold("x")),
  ylab=expression(bold("y"))
 )
brkdn.plot(
  y ~ z+x,data=my.data, mct="mean", md="sd",
  stagger=NA, dispbar=TRUE,
  type="p", pch=c(21, 21, 21, 21), bg=c("blue", "green", "red", "orange"),
  main="z indicated by colour (???)",
  xlab=expression(bold("x")),
  ylab=expression(bold("y"))
 )



More information about the R-help mailing list