<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-signature">Dear List<br>
<br>
I want to present a scatter plot (on time) of soil sample data for
each block in a tree crop, using r. I have a csv file with the
value of the selected attribute, the block name, the x and y, and
the dates for 9 locations, making 34 observations in total. I wish
to present it as a leafpop::popupGraph on a mapview map. The user
will be click on the point(a block centroid) within the block and
see the history/plot for that location only.<br>
<br>
The leafpop package manual provides the svg example using the
meuse data set. Using it as the basis, I have a map with the
points, and the popup. I have not been able to supply only the
plot for the specific block to each point instance within it. My
plot is a faceted ggplot with one facet for each block. Onclick on
the map, each of my 9 locations shows the same full faceted plot
(all 9). I want just the plot for that location.<br>
<br>
The meuse example shows rep iteration through one plot, changing
the colour of the value in that plot to highlight data point for
the geographic location selected. While elegant, it is no guide to
achieving my target.<br>
<br>
Tim Salabim kindly pointed me a step forward suggesting lapply,
but I do have not yet the depth of skill to successfully implement
it. Below is an extract of the code, to show the steps I have
taken so far. <br>
<br>
I am not succeeding at getting the plot images. It also appears
that the process loops through all 34 observations to make plots
for each.<br>
<br>
I am hoping the members can guide me a few steps further forward.<br>
<br>
Here is the code:<br>
block.graph <-
function(select_organic_matter_by_blockname_with_xy_range, na.rm =
TRUE){<br>
<br>
# create list of blocks in data to loop over <br>
block_list <- unique(som_xy$block_name)<br>
<br>
# create for loop to produce ggplot2 graphs <br>
for (i in seq_along(block_list)) { <br>
<br>
# create plot for each block in the dataframe <br>
soil_om <- <br>
ggplot(subset(som_xy,
som_xy$block_name==block_list[i]),<br>
aes(x= date, y = organic_matter)) + <br>
theme_light() +<br>
geom_point() +<br>
ylim(0, 10) +<br>
geom_hline(data = som_xy, linetype="dotted",
colour="#ff710c",alpha = 0.5, aes(yintercept = range_min)) +<br>
geom_hline(data = som_xy, linetype="dotted",
colour="#ff710c",alpha = 0.5, aes(yintercept = range_max))<br>
p <- (soil_om +<br>
theme(<br>
axis.text.x=element_text(angle=90,hjust=1,
vjust=1),<br>
axis.title.x = element_blank(),<br>
axis.title.y = element_text(angle=90,
hjust=0.5),<br>
legend.title = element_blank(),<br>
plot.title = element_text(hjust = 0.5)<br>
)+<br>
ggtitle("Organic Matter Time Series")+<br>
ylab("%"))<br>
}}<br>
individ_plot <- lapply(som_xy$block_name, block.graph)<br>
<br>
mapview(collins_farm,<br>
data = select_organic_matter_by_blockname_with_xy_range,<br>
zcol = "block_name",<br>
popup= leafpop::popupImage(individ_plot))<br>
</div>
<div class="moz-signature"><br>
</div>
<div class="moz-signature">Thanks in advance</div>
<div class="moz-signature">David<br>
</div>
<div class="moz-signature"><br>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr>
<td width="5%" valign="top"> <img
src="https://www.landandwater.com.au/sig_images/lwmsignaturelogo.png"
alt="Land and Water Management logo" width="97"
height="80"> </td>
<td width="95%" valign="top">
<p style="font-family: Tahoma,Geneva,sans-serif; color:
rgb(32, 32, 32); font-size: 13px;"> <strong> David Hine</strong><br>
Land and Water Management PL<br>
Level 7, 127 Creek St<br>
Brisbane, Qld 4000<br>
Australia<br>
<br>
m: 0429 886 146 +61 429 886 146<br>
t: (07) 4015 3470 +61 7 4015 3470<br>
<br>
<!--Suzhou leaflogik Agricultural Information Management Systems Co. Ltd.
Suzhou, Jiangsu, 215163 PR China<br>
m: (+86) 136 1627 2645<br> --> <a
href="https://geoportal.landandwater.com.au/login"
style="color: rgb(93, 116, 255);">GeoPortal</a> with
example presentations of spatial data for horticulture
users and others.<br>
<a href="http://www.landandwater.com.au" style="color:
rgb(93, 116, 255);">Land and Water Management PL</a> </p>
</td>
<td>
<!-- <img src="https://www.landandwater.com.au/sig_images/greendigitaltree_sm.jpg" alt="Merry Christmas" height="208" width="168"> -->
<br>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>