Reputation: 712
I have a dataframe dat
which I use to generate radar plots of different weather conditions (columns) in different sites (denoted by each row arc1045, arc1047 ...) The first two rows of the dataframe are added to indicate the maximum and minimum values of each climatic condition following the example here
ambient_air_temperature relative_humidy barometric_pressure average_wind_speed particulate_density_2.5 particulate_density_10
1 85.000000 100.0000 2000.000 160.000000 999.900000 1999.90000
2 -40.000000 0.0000 10.000 0.000000 0.000000 0.00000
arc1045 9.176667 71.0700 1013.167 4.043333 5.133333 25.16667
arc1047 8.492500 80.9600 1014.000 2.035000 5.600000 25.10000
arc1048 8.477500 76.9875 1012.675 6.842500 6.275000 28.15000
arc1050 8.475000 76.5525 1013.775 6.335000 5.175000 30.20000
I then follow the approach described here to generate URIs of the plots to be included as markers on a leaflet map
library(fmsb)
makePlotURI <- function(expr, width, height, ...) {
pngFile <- plotPNG(function() { expr }, width = width, height = height, ...)
on.exit(unlink(pngFile))
base64 <- httpuv::rawToBase64(readBin(pngFile, raw(1), file.size(pngFile)))
paste0("data:image/png;base64,", base64)
}
rep(makePlotURI(radarchart(dat), 300, 300, bg = "transparent"), 4)
However, here each radar plot contains multiple polygons, with each polygon representing a site. I want each radar plot to have a single polygon and visualize the weather conditions on a single site.
Upvotes: 0
Views: 124
Reputation: 125
It is fairly straightforward to do this, instead of passing the whole data frame to radachart()
function, just pass the required data for one site.
df = data.frame(ambient_air_temp = c(85, -40, 9.176667, 8.492500, 8.477500, 8.475000),
rel_hum = c(100.0000,0.0000,71.0700, 80.9600, 76.9875,76.5525 ),
bar_pre = c(2000.000, 10.000, 1013.167, 1014.000, 1012.675, 1013.775),
ave_ws = c(160,0,4.043333,2.035000,6.842500,6.335000),
pd2.5 = c(999.9, 0, 5.133333, 5.600000, 6.275000, 5.175000),
pd10 = c(1999.9, 0, 25.16667, 25.10000, 28.15000, 30.20000))
row.names(df) = c("1","2","arc1045","arc1047","arc1048","arc1050")
library(fmsb)
pltrd = function(idx) radarchart(df[c(1,2,idx),], title = row.names(df)[idx])
Since your data is in rows = {3,4,5,6}, you can call this function using those row values. Note that rows = {1, 2} are required to be the minimum/maximum values for each variable...
pltrd(3)
pltrd(4)
pltrd(5)
Upvotes: 1