rggplot2ggiraphextraggradar

ggradar returns Error: 'plot.data' contains value(s) > grid.max


Given a sample data as follows:

df <- structure(list(date = c("2022-1-31", "2022-2-28"), PMI = c(50.1, 
50.2), PMI.import = c(48.4, 49), PMI.export = c(47.2, 48.6)), class = "data.frame", row.names = c(NA, 
-2L))

Out:

       date  PMI PMI.import PMI.export
1 2022-1-31 50.1       48.4       47.2
2 2022-2-28 50.2       49.0       48.6

I try to plot a radar plot with codes below, but none of them returns the plots I expected (need to show small difference of three variables in January and Febrary).

library(scales)
library(ggiraphExtra)
library(ggradar)

df %>% 
  mutate_each(funs(rescale), -date) %>%
  ggradar()

enter image description here

ggradar(df,
        values.radar = c("40", "50", "70"),
        grid.min=40, grid.mid=50, grid.max=60
)

enter image description here

and ggradar(df) returns: Error: 'plot.data' contains value(s) > grid.max

Does someone could help? I hope to set y limit ie., between 40~70 or 40~60 to show the small changes of data between two months if it's possible.

Reference:

https://github.com/ricardo-bion/ggradar/issues/7


Solution

  • I think you need to scale your data so that, say, the values 45 - 55 map to the range 0 - 1. Then just label the plot appropriately:

    df %>% 
      mutate(across(contains('PMI'), ~ (.x - 45) / 10)) %>%
      ggradar(values.radar = c('45', '50', '55'))
    

    enter image description here