【问题标题】:Generating radar plots using single dataframe使用单个数据框生成雷达图
【发布时间】:2020-11-05 01:54:15
【问题描述】:

我有一个数据框dat,我用它来生成不同地点的不同天气条件(列)的雷达图(由每一行表示为 arc1045、arc1047 ...)添加数据框的前两行以指示每种气候条件的最大值和最小值如下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

然后我按照here 描述的方法生成要作为标记包含在传单地图上的地块的 URI

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)

但是,这里的每个雷达图都包含多个多边形,每个多边形代表一个站点。我希望每个雷达图都有一个多边形并可视化单个站点上的天气状况。

【问题讨论】:

    标签: r radar-chart


    【解决方案1】:

    这样做相当简单,无需将整个数据框传递给radachart() 函数,只需传递一个站点所需的数据即可。

    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])
    

    由于您的数据位于 rows = {3,4,5,6} 中,因此您可以使用这些行值调用此函数。请注意,rows = {1, 2} 必须是每个变量的最小值/最大值...

    pltrd(3)
    

    pltrd(4)
    

    pltrd(5)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 2020-11-30
      • 2012-10-10
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      • 2017-08-02
      相关资源
      最近更新 更多