Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我在其中添加世界地图代码时,Flex Dashboard不工作_R_Ggplot2_Flexdashboard_Ggplotly - Fatal编程技术网

当我在其中添加世界地图代码时,Flex Dashboard不工作

当我在其中添加世界地图代码时,Flex Dashboard不工作,r,ggplot2,flexdashboard,ggplotly,R,Ggplot2,Flexdashboard,Ggplotly,我已经使用RStudio中的R标记为“新冠病毒-19全球追踪者”创建了一个flex仪表板。我创建了一个直线图、一个面积图和两个柱状图。我想在里面加一张世界热图。 数据如下: 及 . 代码如下: --- title: "COVID-19 WORLDWIDE TRACKER" output: flexdashboard::flex_dashboard: orientation: rows vertical_layout: scroll runtime: shiny --

我已经使用RStudio中的R标记为“新冠病毒-19全球追踪者”创建了一个flex仪表板。我创建了一个直线图、一个面积图和两个柱状图。我想在里面加一张世界热图。 数据如下: 及 . 代码如下:

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

---
标题:“新冠病毒-19全球追踪者”
输出:
flexdashboard::flex_仪表板:
方向:行
垂直布局:滚动
运行时间:闪亮
---
```{r设置,include=FALSE}
库(flexdashboard)
图书馆(GG2)
图书馆(绘本)
图书馆(readxl)
图书馆(世界地图)
图书馆(dplyr)
图书馆(地图)
图书馆(plyr)
图书馆(gridExtra)
x