r - 当我在其中添加世界地图代码时,Flex Dashboard 无法正常工作
问题描述
我在 RStudio 中使用 R Markdown 为“COVID-19 WORLDWIDE TRACKER”创建了一个弹性仪表板。我已经创建了一个线图、一个面积图和 2 个柱形图。我想在其中添加一个世界热图。数据在这里: mydata 和 x。代码如下:
---
title: "COVID-19 WORLDWIDE TRACKER"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(plotly)
library(readxl)
library(rworldmap)
library(dplyr)
library(maps)
library(plyr)
library(gridExtra)
x <- read_excel("owid-covid-data.xlsx")
```
Page 1
===
row {data-height = 350}
---
### World Hotspots
```{r}
library(maps)
library(ggplot2)
mydata <- readxl::read_excel("mapdata1.xlsx")
mydata$Country[mydata$Country == "United States"] <- "USA"
mydata$Country[mydata$Country == "United Kingdom"] <- "UK"
world_map <- map_data("world")
world_map <- subset(world_map, region != "Antarctica")
ggplot(mydata) +
geom_map(
dat = world_map, map = world_map, aes(map_id = region),
fill = "white", color = "#7f7f7f", size = 0.25
) +
geom_map(map = world_map, aes(map_id = Country, fill = Cases), size = 0.25) +
scale_fill_gradient(low = "#fff7bc", high = "#cc4c02", name = "Total Cases") +
expand_limits(x = world_map$long, y = world_map$lat)
```
row {data-height=300}
-----------------------------------------------------------------------
### Top 10 Countries
```{r}
p <- ggplot(x, aes(date, total_cases, color = location)) + geom_line()
ggplotly(p)
```
row {data-height=300}
-----------------------------------------------------------------------
### Daily Comparison of New Cases and Deaths
```{r}
a <- ggplot(x, aes(date, new_cases, fill = location)) + geom_area()
ggplotly(a)
```
row {data-height=400}
-----------------------------------------------------------------------
### Daily Comparison of Total Cases and Deaths
```{r}
b <- ggplot(x, aes(date, total_cases, fill = total_deaths)) + geom_col(position = "dodge")
ggplotly(b)
```
### Top Countries
```{r}
c <- ggplot(x, aes(total_cases_per_million, location)) + geom_col(position = "dodge")
ggplotly(c)
```
没有世界地图代码,仪表板工作得很好。但是当我向其中添加世界地图代码时,仪表板显示一个白屏,根本没有图表。我无法理解为什么会这样。请帮忙!
解决方案
推荐阅读
- c# - 线路抑制状态错误 CS1503 参数 1:无法从“int”转换为“System.Threading.ParameterizedThreadStart”
- r - 如何创建调用 R 脚本的 shell 脚本?
- postgresql - 如何在postgresql中获取三列值的次要
- html - 问题:使用 img 获得无缝选取框效果,但它会明显重新启动
- email - 使用 spfx webparts,是否有办法以编程方式发送一封电子邮件,其中包含打开模式的链接或使用流程?
- python - p4python windows x64构建链接错误
- java - 将包含多个单词的字符串转换为单词向量
- javascript - 使用 javascript 库“turn.js”和 html 创建翻书
- django - Django ModelChoiceField 在列表中显示客户对象(1)等,我如何让它显示客户名称?
- azure - 不能直接在门户中开发第二个Azure功能(只允许在门户中开发第一个功能)