[R] ggplot2 scatterplot matrix

stephen sefick ssefick at gmail.com
Tue Nov 4 15:24:20 CET 2008


#question is below data

library(ggplot2)
d <- (structure(list(Site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L,
7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L,
12L, 12L, 12L), .Label = c("119", "148", "179", "185", "190",
"198", "202", "215", "61", "BC", "HC", "SC"), class = "factor"),
    Date = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L,
    5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
    2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L,
    5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
    2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 2L, 3L, 4L, 5L,
    6L), .Label = c("2006/10", "2006/12", "2007/02", "2007/04",
    "2007/06", "2007/08"), class = "factor"), "1" = c(0.874184606597264,
    0.523739755909531, 0.425703759419943, -2.02051026674766,
    1.16079624161189, 1.45587943803682, 1.19523249092392, 0.566103768560628,
    0.426795468970768, -2.02050068513547, 1.2250428447802, 1.16068384504207,
    -0.151112280286649, -0.989615847672233, -0.372948935657446,
    -2.02096026741509, 0.947185648594073, 0.312498014694392,
    1.32516954991303, 0.108414397872515, -0.0288756641477521,
    -2.02075473660307, 1.01639899740024, 0.722755081936063, 1.08574909138256,
    0.254563596018560, 0.0138769200639356, -2.02086025559366,
    0.253316938104009, 0.97908853547168, -0.0434246965488185,
    0.423661324219902, -0.899190388758309, -2.02218962256833,
    -0.196076706104219, 0.0284392043032882, 0.849595939328728,
    0.0723687090107558, 0.0405236181387585, -2.02217657870515,
    0.346390817233764, 0.0818801769672248, -0.44440392356152,
    0.739657344510278, -0.604851154382727, -2.02404055945549,
    -0.444771150572718, -1.06021257147464, 1.01461402434929,
    0.493107695761646, 0.224559936537548, -2.02402319792585,
    0.671821437959757, 0.91531144342294, 1.06257237085007, -0.521441369728097,
    -1.05942641948463, -2.02387039077251, 0.290605368774526,
    0.295200721242969, 1.89885545000417, 1.97578810202939, 2.20624811826422,
    -2.02406936775965, 0.450034318231514, 1.18954261348381, 0.324828674311005,
    -1.85047346671624, -2.02404758829530, 0.836840410707829,
    0.469201281125742), "2" = c(0.8685685477186, 1.90032361512285,
    2.23038958525376, 0.403357205936226, 0.402752366681005, -0.207820292731955,
    0.507375830781375, 0.627416201911719, 1.15277971834384, 0.402996161559285,
    0.608602722856373, 0.925689975216042, -0.652939446347607,
    -0.526455738083169, 0.186602867205382, 0.404280435221342,
    0.0292513813333443, 0.419346958942841, 0.124358419612639,
    0.360411688194877, 0.371050570522494, 0.404702898397597,
    0.30340028300398, 0.364941099696436, 0.00859460392464377,
    -0.121826374341399, -0.272253136798564, 0.405329642392865,
    -0.709547726504427, -0.84547510102377, -1.34087220358817,
    -1.18053623945451, -1.52784853730614, 0.403750259095273,
    -1.19688141095182, -1.10669413835558, -1.17307319257729,
    -0.783870534841781, -0.795994782683649, 0.402969453005513,
    -1.23419925610224, -1.23079038516171, -1.65245185340749,
    -0.667666712509264, 0.0371195963428637, 0.400885065514325,
    0.245623813009943, -0.827135734652045, 1.18376564048670,
    1.51565400247952, 1.28196020190568, 0.40079465685447, 1.08509284027626,
    0.816227942266177, -0.915908006995306, -0.478325826372955,
    -0.153387609678446, 0.401103544965282, -0.615679846634191,
    -0.388382173033147, 0.793867616891073, 0.734007685905799,
    -0.340897433816939, 0.40026466056969, 0.323130195566442,
    -0.280252644055414, -1.37641434116903, 0.276315327139251,
    0.402544455589003, -0.912607426643162, -1.00141163187162),
    "3" = c(-0.621069558356036, 0.626246924133487, 0.506275647410301,
    -0.286276740359594, -0.917724867702682, -0.65868841716163,
    -0.251533605598756, 0.709776591897396, 0.712222099189896,
    -0.286615232425427, -0.621732506464537, -0.827274034402931,
    -0.760762802823119, -1.03198762310180, 1.60135328558034,
    -0.285578777572489, 0.380910692331262, -0.0760764469985798,
    -0.115157274707272, 1.19185270979311, 2.40625710705576, -0.286701986144124,
    0.249527141423157, -0.117359122323737, 0.270556219210269,
    1.07979573661511, 1.07537415999543, -0.285264245664589, -0.532118288721532,
    -0.337166564931034, -0.878113737326825, 0.637926019463939,
    0.0545342058088365, -0.285770640176988, -0.166159101630537,
    0.0987402357832297, -0.572337894809085, -0.528695330783871,
    0.284122121130382, -0.286608802000579, 0.142899030383526,
    -0.309065687868117, 0.581416221306441, 3.02810228009647,
    1.76544559193858, -0.283082302357854, 1.02312437303847, 0.260739932890114,
    -0.230373780956827, 0.928760155181157, -0.179065943213654,
    -0.284114389489830, -0.991498948929778, -0.701221935776499,
    -0.213461311424286, -0.0689622117191709, 0.0969681764499995,
    -0.283007892210191, -0.625364676165669, -0.492810574347332,
    -1.07206946137426, -0.153334996711174, -0.187153608984751,
    -0.283125264819075, -0.884984271267019, -0.97353665087084,
    0.469192473031129, -0.651808089769573, -0.291130167338813,
    0.129705267865319, -0.135878631220660), "4" = c(-1.00586144653690,
    -0.854035254137794, 0.276210085105099, -0.0950082866835555,
    0.411110732729772, 0.410860811307716, -0.872064917656612,
    -0.355934329351380, 0.439549226877299, -0.09562280284695,
    0.459324491374930, -0.0814488265828821, -1.54127219365431,
    0.409982873438026, -0.183351620560332, -0.0942248063688652,
    0.648842147407866, 1.11331728652053, -0.721838966695388,
    -0.144296373049539, 0.633680000612171, -0.0932069042820532,
    0.0210540185835216, 0.865764261285029, -1.41359006891542,
    -0.0542078820141427, 0.279253046275233, -0.0922098507243485,
    0.163537188513388, -0.0713033160224599, 0.0713190661046374,
    0.176893896796970, 0.83505533916559, -0.0908053109081143,
    -0.169054657764654, 0.182246697373941, 0.333329883863295,
    0.933493173975632, 0.852459111360333, -0.0920324804572333,
    -0.173237058658764, -0.23060044262018, -0.372968517053654,
    -0.114213537948505, 0.132754660556527, -0.0915923803847395,
    -1.25647042406529, 1.01671379828056, -0.101926357721247,
    -0.207224613849714, 0.671468385159091, -0.0917636610205257,
    -0.00911314383383064, -0.247187676197257, -1.02301101006491,
    0.936860503420404, 0.404881083610545, -0.0941428418509214,
    -0.56402509137652, -0.888790816910229, 1.26955596195453,
    1.13193828940451, 0.0421716610255368, -0.0934944376161769,
    -0.183641841456159, -0.214425700829426, 0.65066474141576,
    0.183584777653985, -0.0923159216753842, -0.933622602166743,
    -0.852738828639321)), .Names = c("Site", "Date", "1", "2",
"3", "4"), row.names = c("119 2006/10", "119 2006/12", "119 2007/02",
"119 2007/04", "119 2007/06", "119 2007/08", "148 2006/10", "148 2006/12",
"148 2007/02", "148 2007/04", "148 2007/06", "148 2007/08", "179 2006/10",
"179 2006/12", "179 2007/02", "179 2007/04", "179 2007/06", "179 2007/08",
"185 2006/10", "185 2006/12", "185 2007/02", "185 2007/04", "185 2007/06",
"185 2007/08", "190 2006/10", "190 2006/12", "190 2007/02", "190 2007/04",
"190 2007/06", "190 2007/08", "198 2006/10", "198 2006/12", "198 2007/02",
"198 2007/04", "198 2007/06", "198 2007/08", "202 2006/10", "202 2006/12",
"202 2007/02", "202 2007/04", "202 2007/06", "202 2007/08", "215 2006/10",
"215 2006/12", "215 2007/02", "215 2007/04", "215 2007/06", "215 2007/08",
"61 2006/10", "61 2006/12", "61 2007/02", "61 2007/04", "61 2007/06",
"61 2007/08", "BC 2006/10", "BC 2006/12", "BC 2007/02", "BC 2007/04",
"BC 2007/06", "BC 2007/08", "HC 2006/10", "HC 2006/12", "HC 2007/02",
"HC 2007/04", "HC 2007/06", "HC 2007/08", "SC 2006/12", "SC 2007/02",
"SC 2007/04", "SC 2007/06", "SC 2007/08"), class = "data.frame"))

plotmatrix(d[,3:6])

I would like to either have a colour or more preferably a shape to
correspond to Site
this is what I have tried (along with many other combinations)
plotmatrix(nmds.bug[,3:6])+scale_shape(nmds.bug, shape=Site, pch=1:12)

thanks

-- 
Stephen Sefick
Research Scientist
Southeastern Natural Sciences Academy

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

								-K. Mullis



More information about the R-help mailing list