警告在 RShiny 中变为错误:忽略未知的美学:文本

Warning gets to Error in RShiny: Ignoring unknown aesthetics: text

我正在执行以下操作:

## Get the world map: ##
worldMap <- getMap()

## Define vector with all European countries: ##
v.europe <- c("Norway", "Sweden", "Finland", "Denmark", "United Kingdom","Ireland", "Greece",
              "Belgium", "Netherlands", "France", "Spain", "Portugal", "Luxembourg", "Croatia",
              "Germany", "Switzerland", "Austria", "Slovenia", "Italy", "Bulgaria", "Romania",
              "Czech Rep.", "Slovakia", "Hungary", "Poland", "Bosnia Hercegovina", "Serbia",
              "Turkey", "Ukraine", "Moldova", "Belarus", "Estonia", "Latvia", "Lithuania",
              "Montenegro", "Albania", "Macedonia")
              
## Select only the index of countries of Europe: ##
indEU <- which(worldMap$NAME%in%v.europe)


## Extract longitude and latitude border's coordinates of countries: ##
df.europeCoords <- lapply(indEU, function(i){
    df <- data.frame(worldMap@polygons[[i]]@Polygons[[1]]@coords)
    df$region = as.character(worldMap$NAME[i])
    colnames(df) <- list("long", "lat", "region")
    return(df)
})
df.europeCoords <- do.call("rbind", df.europeCoords)
names(df.europeCoords) <- c("longitude", "latitude", "country")

## Mean values of some of the countries of Europe: ##
meanGermany <- 33.33
meanAustria <- 35.71
meanNetherlands <- 35.9
meanBelgium <- 34.66
meanFrance <- 34.89
meanItaly <- 43.97
meanHungary <- 43.96
meanCroatia <- 42.54
meanBulgaria <- 54.61
meanGreece <- 25.72
meanNorway <- 27.64
meanSweden <- 36.41
meanFinland <- 32.13
meanDenmark <- 36.83
meanSlovakia <- 35.94
meanCzechia <- 44.15
meanRomania <- 36.52
meanSwitzerland <- 44.12
meanSerbia <- 45.53
meanSlovenia <- 45.1

## Create vector with mean values: ##
v.meanValues <- c('Germany' = meanGermany, 'Austria' = meanAustria, 'Netherlands' = meanNetherlands,
                  'Belgium' = meanBelgium, 'France' = meanFrance, 'Italy' = meanItaly, 'Greece' = meanGreece,
                  'Hungary' = meanHungary, 'Croatia' = meanCroatia, 'Bulgaria' = meanBulgaria,
                  'Norway' = meanNorway, 'Sweden' = meanSweden, 'Finland' = meanFinland, 'Denmark' = meanDenmark,
                  'Slovakia' = meanSlovakia, 'Czech Rep.' = meanCzechia, 'Romania' = meanRomania,  
                  'Serbia' = meanSerbia, 'Slovenia' = meanSlovenia, 'Switzerland' = meanSwitzerland)

## Merge mean values with European countries: ##
df.europeCoords$meanValues <- v.meanValues[match(df.europeCoords$country, names(v.meanValues))]


## Read Excel-file with longitude and latitude of each country: ##
df.longLat <- read_excel("C:/Users/z_kordasch/Documents/fire/server/input_Data/EUROPE_LongitudeLatitude.xlsx", na = "NA")

## Merge mean values to this new data frame: ##
df.longLat$meanValues <- v.meanValues[match(df.longLat$country, names(v.meanValues))]



## Deletes/Removes borders of PLOT: ##
ax <- list(
  title = "",
  zeroline = FALSE,
  showline = FALSE,
  showticklabels = FALSE,
  showgrid = FALSE
)

当我绘制欧洲地图时,我收到错误信息 警告:忽略未知的美学:文本,我在 geom_polygon() 中使用 text = paste("<b>", country, '</b>') .请参阅下一个代码片段:

## Plot the map: ##
p <- ggplot() + 
     geom_polygon(data = df.europeCoords, 
                  aes(x = longitude, y = latitude, 
                      group = country, fill = meanValues, 
                      text = paste("<b>", country, '</b>')),
                  color = "black", size = 0.1) +
     coord_map(xlim = c(-13, 35),  ylim = c(32, 71)) +
     theme_classic() +
     scale_fill_gradient(name = "Price Mean Values", low = "#81C07A", 
                         high = "#007d3c", na.value = "#CCCCCC") +
     theme(axis.text.x = element_blank(), 
           axis.text.y = element_blank(), 
           axis.ticks.x = element_blank(),
           axis.ticks.y = element_blank(), 
           axis.title = element_blank(), 
           legend.position = "none",
           plot.margin = unit(0 * c(-1.5, -1.5, -1.5, -1.5), "lines")) +
     geom_text(data = df.longLat, aes(long, lat, label = meanValues), size = 2)
                  
## Generate ggplot() to plot_ly() object: ##
EuropePlot <- plotly::ggplotly(p, tooltip = "text") %>%
              layout(xaxis = ax, yaxis = ax)

剧情是这样的:

问题是 R 中的警告没有影响,因为它仍然绘制了所需的结果。在 Shiny App 中调用时,没有任何显示,正是因为这个警告。它应该在 RShiny 中以相同的方式工作,所以我必须以某种方式解决这个警告。 我该如何解决这个问题 issue/problem?

我已经解决了以下问题:

  ## Plot the map: ##
  p <- ggplot(data = df.europeCoords, aes(x = longitude, y = latitude, group = country, 
                                          fill = meanValues, text = paste("<b>", country, '</b>\n')),  
              color = "black", size = 0.1) + 
       geom_polygon() +
       coord_map(xlim = c(-13, 35),  ylim = c(32, 71)) +
       theme_classic() +
       scale_fill_gradient(name = "Price Mean Values", low = "#81C07A", high = "#007d3c", 
                           na.value = "#CCCCCC") +
       theme(axis.text.x = element_blank(), axis.text.y = element_blank(), 
             axis.ticks.x = element_blank(), axis.ticks.y = element_blank(), 
             axis.title = element_blank(),  legend.position = "none",
             plot.margin = unit(0 * c(-1.5, -1.5, -1.5, -1.5), "lines")) +
       geom_text(data = df.longLat, aes(x = long, y = lat, label = meanValues), size = 2)
  
  ## Generate ggplot() to plot_ly() object: ##
  EuropePlot <- plotly::ggplotly(p, tooltip = "text") %>%
                layout(xaxis = ax, yaxis = ax)