小编kbr*_*ner的帖子

D3.js:如何组合 2 个数据集以创建地图并在鼠标悬停时显示值?

我想在 D3.js 中的地图上合并两个数据集。

例如:

第一个数据集:.json 格式的空间数据。

第二个数据集:.csv 中区域的数据

--> 当您将鼠标悬停在地图上时,工具提示应显示一个句子,其中包含第二个数据集中的一些数据。

我可以制作地图并显示包含 .json 文件中数据的工具提示,但如何插入第二个数据集?

  • 我的函数中创建地图的新函数?
  • 我必须采取全新的方式吗?
  • 在使用 d3.js 之前,我应该将 .json 文件与第二个数据集合并吗?

我很感激任何想法!:)

csv json geocoding d3.js

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

是否可以在R和/或LeafletR的htmlwidgets中包含自定义css?

我想对我的传单地图进行一些样式更改.

是否可以包括

  • 风格元素或
  • css文件的自定义路径

通过htmlwidgets为R或LeafletR?

最好

r leaflet htmlwidgets

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

dplyr + ggplot2:绘图不通过管道工作

我想绘制我的数据帧的子集.我正在使用dplyr和ggplot2.我的代码仅适用于版本1,而不适用于通过管道版本2.有什么不同?

版本1(绘图工作):

data <- dataset %>% filter(type=="type1")
ggplot(data, aes(x=year, y=variable)) + geom_line()
Run Code Online (Sandbox Code Playgroud)

版本2带管道(绘图不起作用):

data %>% filter(type=="type1") %>% ggplot(data, aes(x=year, y=variable)) + geom_line()
Run Code Online (Sandbox Code Playgroud)

错误:

Error in ggplot.data.frame(., data, aes(x = year,  : 
Mapping should be created with aes or aes_string
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

r ggplot2 dplyr

4
推荐指数
2
解决办法
1万
查看次数

Maps with R: Can't change the projection for points/coordinates

I want to plot a world map with multiple points aka combinations of latitude and longitude coordinates.

I don't want to use Mercator, therefore I re-project both, the data for the world map and my coordinates.

While the projection for the world changes, all points are suddenly placed in the middle of the map (a common behavior, when the projections don't align, see https://www.earthdatascience.org/courses/earth-analytics/spatial-data-r/intro-to-coordinate-reference-systems/).

What am I doing wrong in when assigning the projection to the points?

My code: …

r spatial ggplot2 r-sf

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

Quarto:在 Quarto 网站中创建闪亮的交互式 qmd 文档

我正在构建一个 Quarto 网站(https://quarto.org/docs/websites/),该网站应该有一些与 Shiny 交互工作的页面。

假设这个迷你交互式文件应命名为mini-app.qmd

---
title: "Old Faithful"
format: html
server: shiny
---

```{r}
sliderInput("bins", "Number of bins:", 
            min = 1, max = 50, value = 30)
plotOutput("distPlot")
```

```{r}
#| context: server
output$distPlot <- renderPlot({
  x <- faithful[, 2]  # Old Faithful Geyser data
  bins <- seq(min(x), max(x), length.out = input$bins + 1)
  hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
```
Run Code Online (Sandbox Code Playgroud)

这就像一个普通.qmd文件一样,渲染、预览,一切都很棒。

但是,一旦此文件mini-app.qmd成为使用此交互式组件创建的四开本的一部分,quarto create-project …

r shiny quarto

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

如何使用 xml2 和 purrr 提取不同级别的 xml_attr 和 xml_text?

我想从 XML 文件中提取信息并将其转换为数据框架。

信息以 XML 文本和 XML 属性的形式存储在嵌套节点中:

结构示例:

<xmlnode node-id = "Text about xmlnode">
    <xmlsubnode subnode-id = "123">
        <xmlsubsubnode>
            I want to extract this text
        </xmlsubsubnode>
        <xmlsubsubnode>
            I want to extract this text
        </xmlsubsubnode>    
        <xmlsubsubnode>
            I want to extract this text
        </xmlsubsubnode>    
        <xmlsubsubnode>
            I want to extract this text
        </xmlsubsubnode>    
    </xmlsubnode>
    <xmlsubnode subnode-id = "456">
        <xmlsubsubnode>
            I want to extract this text
        </xmlsubsubnode>
        <xmlsubsubnode>
            I want to extract this text
        </xmlsubsubnode>    
        <xmlsubsubnode>
            I want to extract this text
        </xmlsubsubnode> …
Run Code Online (Sandbox Code Playgroud)

r dplyr xml2 purrr tidyverse

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

Quarto/RMarkdown 到 PDF:如何增加表格子标题之间的边距?

我使用 Quarto/RMarkdown 导出一个 PDF,其中包含一个代码块,该代码块可生成两个表(包括)。子帽。

如何增加下层子上限与上层表格的边距?

我的代码:

#| label: tbl-1985
#| tbl-cap: "*Was Wann Wo* im Jahr 1985"
#| tbl-subcap: 
#|   - "Auswertung nach Kategorien"
#|   - "Besonderheiten"
#| layout-nrow: 2
#| fig-pos: 'H'

# table 1
df_table_1 %>% 
    knitr::kable(., caption = paste0("\\textit{Was Wann Wo} im Jahr ", year)) %>%
    kableExtra::kable_styling(latex_options = "scale_down")

# table 2
df_table_2 %>% 
    knitr::kable(., caption = paste0("Besonderheiten im Jahr ", year)) %>% 
    kableExtra::column_spec(2, width = "12cm")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

latex pandoc r-markdown kable quarto

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

如何将字符串转换为 R 中“语言”类型的公式?

我想将带有公式的字符串转换为带有该类型的对象,language以便将其用作公式。

我怎样才能做到这一点?

一个简短的例子,显示了这个问题:

formula <- "(1 - sin(x^3)"
> typeof(formula)
[1] "character"
Run Code Online (Sandbox Code Playgroud)

工作参考是

> typeof(quote(1 - sin(x^3)))
[1] "language"
Run Code Online (Sandbox Code Playgroud)

当然,我不能只在引用中写公式:

> quote(formula)
formula
Run Code Online (Sandbox Code Playgroud)

那么,有没有办法将向量中的字符串转换为 typeof 的内容language

r

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

标签 统计

r ×6

dplyr ×2

ggplot2 ×2

quarto ×2

csv ×1

d3.js ×1

geocoding ×1

htmlwidgets ×1

json ×1

kable ×1

latex ×1

leaflet ×1

pandoc ×1

purrr ×1

r-markdown ×1

r-sf ×1

shiny ×1

spatial ×1

tidyverse ×1

xml2 ×1