Circles in legend for leaflet map with addCircleMarkers in R - without shiny(带有 R 中 addCircleMarkers 的传单地图的传说中的圆圈 - 没有闪亮)
问题描述
我正在 R 中创建传单地图 - 我不需要构建一个闪亮的应用程序,并且还没有解决那个特定的技能集!
我试图在这里跟随这篇文章在我的传奇中创建圈子:
从原始答案中,您省略了一组负责圆形的全局样式定义.
将 border-radius: 50%;
添加到 colorAdditions
一组 css 样式中,这是您需要的一种样式.
这将使:
colorAdditions <- paste0(colors, ";border-radius: 50%; width:", sizes, "px; height:", sizes, "px")
有点hacky,但可以.
I am creating a leaflet map in R - I don't need to build a shiny app, and haven't tackled that particular skill set yet!
I was trying to follow along with this post here to create circles in my legend: Creating legend with circles leaflet R .
However, I'm not sure how to incorporate the tags$style
attribute to my R code as @K. Rhode suggested to ensure the legend items are circles. In my code, the legend comes up with squares. So close!
Can anyone help me nudge this code into making the legend items circles?
library(leaflet)
library(dplyr)
#create data
Points<-data.frame(x=runif(10,20,21), y=runif(10,0,1),
var=c(rep(c(10,20, 40),3), 20))
Points <- Points %>%
mutate(Category = case_when(var == 10 ~ "A",
var == 20 ~ "B",
TRUE ~ "C"),
color = case_when(Category == "A" ~ "blue",
Category == "B" ~ "blue",
TRUE ~ "red"))
map = leaflet() %>%
addTiles()
addLegendCustom <- function(map, colors, labels, sizes, opacity = 0.5){
colorAdditions <- paste0(colors, "; width:", sizes, "px; height:", sizes, "px")
labelAdditions <- paste0("<div style='display: inline-block;height: ",
sizes, "px;margin-top: 4px;line-height: ", sizes, "px;'>",
labels, "</div>")
return(addLegend(map, colors = colorAdditions,
labels = labelAdditions, opacity = opacity))
}
map %>%
addCircleMarkers(Points$x,Points$y,radius=Points$var,
color = Points$color,
stroke = FALSE, fillOpacity = 0.5) %>%
addLegendCustom(colors = c("blue", "blue", "red"),
labels = c("A", "B", "C"), sizes = c(10, 20, 40))
In the legend I'd prefer circle markers... not squares as below!
From the original answer, you omitted one set of global style definition that is responsible for the round shape.
Add border-radius: 50%;
to the colorAdditions
set of css styles, which is the one style you are needing from it.
This would make:
colorAdditions <- paste0(colors, "; border-radius: 50%; width:", sizes, "px; height:", sizes, "px")
A bit hacky, but works.
这篇关于带有 R 中 addCircleMarkers 的传单地图的传说中的圆圈 - 没有闪亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 R 中 addCircleMarkers 的传单地图的传说中的圆圈 - 没有闪亮
基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01