r - Add duplicate xyplot in lattice -
this first post i'm not sure if i've done correctly. i'd add second xyplot plot1 represents same data bubble plot (percent~distance , grouped forest_type), without size of bubble based on dat$pixels. ie: dot within bubble. dots should black , small. tried as.layer latticeextra, couldn't work limited panel , function experience. obtained original code more experienced , have been able modify slightly. suggestions.
library(lattice) mykey <- list(x = .7, y = .7, corner = c(0,1), text = list(lab = c("d", "c", "m")), points = list(col = c(2,3,4), pch = 1) ) fontsize <- trellis.par.get("par.main.text") fontsize$font <- 1 trellis.par.set("par.main.text", fontsize) trellis.par.get() plot1<-xyplot(percent ~ distance, key = mykey, cex = dat$pixels / 15000000, col = dat$forest_type+1, xlab="distance", ylab="percent of pixels", data = dat, panel = function(...){ panel.xyplot(...) }) print(plot1, position=c(0, .5, 1, 1))
data reproduce/use below:
dat <- structure(list(pixels = c(51442200l, 16201800l, 9679500l, 8954100l, 4332600l, 4024800l, 2843100l, 2707200l, 2635200l, 1754100l, 1865700l, 1467000l, 1575900l, 1253700l, 1061100l, 1205100l, 1045800l, 909000l, 822600l, 732600l, 837900l, 676800l, 600300l, 538200l, 504900l, 414000l, 316800l, 318600l, 260100l, 261900l, 214200l, 189900l, 182700l, 178200l, 150300l, 135000l, 117000l, 103500l, 90000l, 95400l, 68400l, 79200l, 69300l, 54900l, 72000l, 60300l, 55800l, 41400l, 41400l, 37800l, 24300l, 25200l, 32400l, 36000l, 28800l, 19800l, 18900l, 16200l, 16200l, 60586200l, 25074900l, 18993600l, 21714300l, 13090500l, 13913100l, 10777500l, 11007900l, 11732400l, 8385300l, 9188100l, 7379100l, 8556300l, 7248600l, 6276600l, 7616700l, 6766200l, 6323400l, 5963400l, 5404500l, 6618600l, 5781600l, 5630400l, 5091300l, 5515200l, 4810500l, 4392900l, 4674600l, 4113900l, 4517100l, 3974400l, 3650400l, 3759300l, 3761100l, 3456000l, 3180600l, 2963700l, 2999700l, 2619000l, 2723400l, 2321100l, 2286000l, 2167200l, 1925100l, 1906200l, 1649700l, 1658700l, 1561500l, 1567800l, 1494900l, 1378800l, 1384200l, 1219500l, 1257300l, 1220400l, 1098000l, 1133100l, 959400l, 1044900l, 3713400l, 1295100l, 827100l, 892800l, 549000l, 561600l, 440100l, 432900l, 461700l, 319500l, 344700l, 248400l, 277200l, 221400l, 185400l, 227700l, 222300l, 206100l, 189900l, 177300l, 209700l, 189900l, 170100l, 156600l, 170100l, 163800l, 153900l, 169200l, 148500l, 185400l, 162000l, 165600l, 176400l, 149400l, 128700l, 111600l, 99000l, 83700l, 60300l, 48600l, 32400l, 27000l, 12600l, 6300l, 5400l, 8100l, 9000l, 11700l, 15300l, 16200l, 11700l, 10800l, 6300l, 5400l, 6300l, 9900l, 14400l, 15300l, 15300l), forest_type = c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l, 3l), distance = c(30l, 60l, 90l, 120l, 150l, 180l, 210l, 240l, 270l, 300l, 330l, 360l, 390l, 420l, 450l, 480l, 510l, 540l, 570l, 600l, 630l, 660l, 690l, 720l, 750l, 780l, 810l, 840l, 870l, 900l, 930l, 960l, 990l, 1020l, 1050l, 1080l, 1110l, 1140l, 1170l, 1200l, 1230l, 1260l, 1290l, 1320l, 1350l, 1380l, 1410l, 1440l, 1470l, 1500l, 1530l, 1560l, 1590l, 1620l, 1650l, 1680l, 1710l, 1740l, 1770l, 30l, 60l, 90l, 120l, 150l, 180l, 210l, 240l, 270l, 300l, 330l, 360l, 390l, 420l, 450l, 480l, 510l, 540l, 570l, 600l, 630l, 660l, 690l, 720l, 750l, 780l, 810l, 840l, 870l, 900l, 930l, 960l, 990l, 1020l, 1050l, 1080l, 1110l, 1140l, 1170l, 1200l, 1230l, 1260l, 1290l, 1320l, 1350l, 1380l, 1410l, 1440l, 1470l, 1500l, 1530l, 1560l, 1590l, 1620l, 1650l, 1680l, 1710l, 1740l, 1770l, 30l, 60l, 90l, 120l, 150l, 180l, 210l, 240l, 270l, 300l, 330l, 360l, 390l, 420l, 450l, 480l, 510l, 540l, 570l, 600l, 630l, 660l, 690l, 720l, 750l, 780l, 810l, 840l, 870l, 900l, 930l, 960l, 990l, 1020l, 1050l, 1080l, 1110l, 1140l, 1170l, 1200l, 1230l, 1260l, 1290l, 1320l, 1350l, 1380l, 1410l, 1440l, 1470l, 1500l, 1530l, 1560l, 1590l, 1620l, 1650l, 1680l, 1710l, 1740l, 1770l), percent = c(44.44565403, 38.05758742, 32.81164195, 28.37059427, 24.10736642, 21.75626368, 20.22018818, 19.13486005, 17.77022516, 16.77136219, 16.36794315, 16.1306284, 15.13920111, 14.37119571, 14.10455796, 13.31675783, 13.01669094, 12.22020569, 11.79202684, 11.60205245, 10.92979573, 10.18004603, 9.378515186, 9.301602115, 8.156440826, 7.683313847, 6.51369356, 6.171548117, 5.751243781, 5.275562001, 4.923458833, 4.740507751, 4.436188811, 4.358353511, 4.024096386, 3.93907563, 3.679592414, 3.24767015, 3.249918752, 3.327055869, 2.824228911, 3.31075997, 3.081232493, 2.763932941, 3.629764065, 3.509690938, 3.237597911, 2.564102564, 2.548476454, 2.440441604, 1.717557252, 1.774397972, 2.575107296, 2.772002772, 2.29390681, 1.755786113, 1.62037037, 1.634877384, 1.505016722, 52.34599773, 58.90025792, 64.38464824, 68.80061595, 72.83789874, 75.20797859, 76.64981118, 77.80534351, 79.11634399, 80.17382325, 80.60797473, 81.13805047, 82.1978212, 83.09089033, 83.43103242, 84.16708105, 84.21642209, 85.00907441, 85.48574377, 85.59007982, 86.33482038, 86.96358468, 87.9640045, 87.99191165, 89.09566735, 89.27676633, 90.32198372, 90.55090656, 90.96517413, 90.98984772, 91.35291684, 91.12558976, 91.28059441, 91.98767334, 92.53012048, 92.80462185, 93.20690631, 94.12595312, 94.57263568, 94.97802888, 95.83797845, 95.56057186, 96.35854342, 96.91889443, 96.09800363, 96.01885804, 96.24020888, 96.71125975, 96.50969529, 96.51365485, 97.45547074, 97.46514575, 96.9241774, 96.81219681, 97.20430108, 97.36632083, 97.14506173, 96.82107175, 97.0735786, 3.208348237, 3.042154666, 2.803709805, 2.82878978, 3.054734839, 3.035757723, 3.13000064, 3.059796438, 3.113430843, 3.05481456, 3.024082116, 2.731321128, 2.662977693, 2.537913959, 2.464409618, 2.516161114, 2.766886972, 2.770719903, 2.72222939, 2.807867731, 2.735383893, 2.856369297, 2.657480315, 2.706486234, 2.747891829, 3.039919826, 3.164322724, 3.277545328, 3.28358209, 3.734590283, 3.723624328, 4.133902494, 4.283216783, 3.653973145, 3.445783133, 3.256302521, 3.113501274, 2.62637673, 2.177445564, 1.694915254, 1.337792642, 1.128668172, 0.56022409, 0.317172633, 0.272232305, 0.471451021, 0.522193211, 0.724637681, 0.941828255, 1.045903544, 0.82697201, 0.760456274, 0.500715308, 0.415800416, 0.501792115, 0.877893057, 1.234567901, 1.544050863, 1.421404682), div2erroftot = c(4.966434556, 1.564186201, 0.934497422, 0.864464421, 0.418286433, 0.388570197, 0.27448418, 0.261363854, 0.254412687, 0.169347789, 0.180122097, 0.141630014, 0.152143653, 0.121037184, 0.102442814, 0.116345146, 0.100965691, 0.087758475, 0.079417075, 0.070728117, 0.080894198, 0.065340963, 0.057955349, 0.051959968, 0.048745054, 0.039969206, 0.030585132, 0.030758911, 0.025111088, 0.025284867, 0.02067972, 0.018333701, 0.017638585, 0.017204137, 0.01451056, 0.013033437, 0.011295645, 0.009992302, 0.008688958, 0.009210295, 0.006603608, 0.007646283, 0.006690498, 0.005300264, 0.006951166, 0.005821602, 0.005387154, 0.003996921, 0.003996921, 0.003649362, 0.002346019, 0.002432908, 0.003128025, 0.003475583, 0.002780467, 0.001911571, 0.001824681, 0.001564012, 0.001564012, 5.849232678, 2.42083056, 1.833717675, 2.096384872, 1.263808926, 1.343226002, 1.040502708, 1.062746441, 1.132692552, 0.809550207, 0.887055712, 0.712407658, 0.826059227, 0.699808669, 0.605967924, 0.735346507, 0.653235855, 0.610486182, 0.57573035, 0.521771922, 0.638985964, 0.558178655, 0.543581206, 0.491534348, 0.53245934, 0.4644248, 0.424108035, 0.451304473, 0.397172266, 0.436098797, 0.383704381, 0.352424132, 0.362937771, 0.363111551, 0.333655983, 0.307067772, 0.286127384, 0.289602967, 0.252848675, 0.262927866, 0.224088224, 0.220699531, 0.209230106, 0.185856809, 0.184032128, 0.159268598, 0.160137494, 0.15075342, 0.151361647, 0.144323591, 0.133114835, 0.133636172, 0.11773538, 0.121384742, 0.117822269, 0.106005286, 0.10939398, 0.092624291, 0.100878801, 0.358506403, 0.125034104, 0.079851523, 0.086194462, 0.053002643, 0.054219097, 0.042489004, 0.041793887, 0.044574354, 0.030845801, 0.033278709, 0.023981524, 0.02676199, 0.021374836, 0.017899253, 0.021983063, 0.021461726, 0.019897714, 0.018333701, 0.017117247, 0.020245272, 0.018333701, 0.01642213, 0.015118787, 0.01642213, 0.015813903, 0.014858118, 0.016335241, 0.014336781, 0.017899253, 0.015640124, 0.015987683, 0.017030357, 0.01442367, 0.01242521, 0.010774308, 0.009557854, 0.008080731, 0.005821602, 0.004692037, 0.003128025, 0.002606687, 0.001216454, 0.000608227, 0.000521337, 0.000782006, 0.000868896, 0.001129565, 0.001477123, 0.001564012, 0.001129565, 0.001042675, 0.000608227, 0.000521337, 0.000608227, 0.000955785, 0.001390233, 0.001477123, 0.001477123)), .names = c("pixels", "forest_type", "distance", "percent", "div2erroftot"), class = "data.frame", row.names = c(na, -177l))
if understand correctly, simple enough can handled modified panel function.
the panel function below first runs panel.xyplot(x,y,...)
plot have, , adds small black points using function lpoints()
, lattice's grid-based version of base graphics function points()
.
try this:
plot1<-xyplot(percent ~ distance, key = mykey, cex = dat$pixels / 15000000, col = dat$forest_type+1, xlab="distance", ylab="percent of pixels", data = dat, panel = function(x,y,...){ panel.xyplot(x,y,...) lpoints(x, y, col="black", pch=16, cex=0.01) }) print(plot1, position=c(0, .5, 1, 1))
Comments
Post a Comment