小编Luk*_*ner的帖子

在传单图例中创建自定义标签

地图图像

我在传单中创建了一张地图。图例当前编号为 0、2、4、6、8。但是,我只想要两个标签。一个说“较不密集”,另一个说“较密集”。

我目前正在使用一个合并到列的形状文件来记录每个国家的人口密度。

在此先感谢您的帮助。

我的地图看起来像这样,如附图所示。

这是我当前用于创建地图的代码

library(here) #create wkd
library(utils) #unzip file
library(rgdal) #read the shape file
library(dplyr) #clean the data
library(leaflet) #creates interactive graph
library(RColorBrewer) #modifies colour pallette with custom bins
library(viridis) #allows for additional colour pallettes

# Create a color palette for the map:

# Call the color function (colorBin) to create a new palette function. Domain allows the colouring of continuous data

mypalettepop <- colorNumeric( palette="Purples", domain=worldCountries@data$pop_density_log)

# Pass the palette function a data vector to …
Run Code Online (Sandbox Code Playgroud)

label r legend leaflet

3
推荐指数
1
解决办法
2029
查看次数

if 逻辑的 if 语句至少包含一个 TRUE (R)

我正在创建一个 if 语句来判断输出是否包含特定字符串。我正在使用正则表达式来执行此操作。

我正在使用 grepl() 函数来调查输出是否在变量“stockfish_response”中包含字符串“最终评估:无(检查中)”。然后,它包含一个由 FALSE 和 TRUE 组成的逻辑矩阵。例如:

假假假假假假真

grepl('Final evaluation: none \\(in check\\)', stockfish_response) 
Run Code Online (Sandbox Code Playgroud)

为了将其合并到 IF ELSE 语句中,我需要一个逻辑过程来检查该矩阵中是否至少存在一次 TRUE。是否有一个函数,如果逻辑矩阵至少包含一个 TRUE,则返回 TRUE;如果逻辑矩阵不包含 TRUE,则返回 FALSE。

例如:

grepl_output <- grepl('Final evaluation: none \\(in check\\)', stockfish_response) 

if (grepl_output == TRUE){
  print('the phrase \'Final evaluation: none (in check) string \' exists')
} else {
  print('the phrase \'Final evaluation: none (in check) string \' does not exist')
}
Run Code Online (Sandbox Code Playgroud)

其中 grepl_output == TRUE 不仅限于列表中的第一个逻辑,并且如果列表中的任何值为 TRUE 则返回 TRUE

if-statement r logical-operators

1
推荐指数
1
解决办法
812
查看次数

标签 统计

r ×2

if-statement ×1

label ×1

leaflet ×1

legend ×1

logical-operators ×1