警告进入RShiny错误:忽略未知的美学:文本

问题描述

我正在执行以下操作:

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

在绘制欧洲地图时,出现错误按摩警告:忽略未知的美学:文字,在text = paste("<b>",country,'</b>')中使用geom_polygon()。请参见下一个代码段:

## Plot the map: ##
p <- ggplot() + 
     geom_polygon(data = df.europeCoords,aes(x = longitude,y = latitude,group = country,fill = meanValues,text = paste("<b>",'</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),"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)

情节如下:

enter image description here

问题在于R中的警告不会打扰,因为它仍在绘制所需的结果。正是由于此警告,当在Shiny App中调用时,没有任何显示。它应该在RShiny中以相同的方式工作,所以我必须以某种方式解决此警告。 我该如何解决这个问题/问题?

解决方法

我已经解决了以下问题:

  ## 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),"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)