- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
图例和标签(州缩写)未在 Shiny 应用程序的美国等值区中显示。但是,当我在 RStudio 控制台的 global.R 函数中运行代码时,标签和图例都显示正常。请帮忙!
代码如下:
global.R
#install.packages("Quandl")
library(Quandl)
library(lubridate)
library(rMaps)
library(plyr)
library(shiny)
library(reshape2)
library(rCharts)
getData <- function()
{
birth.rate <- Quandl("CDC/42512_40827_00")
birth.rate
}
transformData <- function()
{
birth.rate <- Quandl("CDC/42512_40827_00")
birth.rate <- melt(birth.rate, variable.name = 'State', value.name = 'Birth.Rate', id = 'Year')
b <- transform(birth.rate, State = state.abb[match(State, state.name)],
Year = year(birth.rate$Year),
fillKey = cut(Birth.Rate, quantile(Birth.Rate, seq(0, 1, 1/4)),
include.lowest=TRUE, labels = LETTERS[1:4]))
b[is.na(b)] <- "DC"
b
}
createMap <- function(data)
{
fillColors <- setNames(
RColorBrewer::brewer.pal(4, 'Greens'),
c(LETTERS[1:4])
)
d <- Datamaps$new()
fml = lattice::latticeParseFormula(Birth.Rate~State, data = data)
d$set(
scope = 'usa',
data = dlply(data, fml$right.name),
fills = as.list(fillColors),
legend = TRUE,
labels = TRUE)
d
}
服务器:
source('global.R')
b <- transformData()
shinyServer(function(input, output) {
output$animatedChart = renderChart({
animatedChart=createMap(b[b$Year==input$Year,]
)
animatedChart$addParams(dom = 'animatedChart')
return(animatedChart)
})
})
用户界面:
library(shiny)
shinyUI(bootstrapPage(
div(class="row",
div(class="span4",
sliderInput("Year","", min=1990, max=2009, value=1990,step=1))),
mainPanel(
showOutput("animatedChart","datamaps") )
))
最佳答案
事实证明,rCharts 中的“DataMaps”库版本不显示图例和标签,但 rMaps 会显示图例和标签。当这两个包都加载到 Shiny 中时,它默认使用“DataMaps”的 rCharts 版本。我不得不更改 ui.R 中的代码以改为使用“rMaps”包。
更正的用户界面:
library(shiny)
shinyUI(bootstrapPage(
div(class="row",
div(class="span4",
sliderInput("Year","", min=1990, max=2009, value=1990,step=1))),
mainPanel(
showOutput("animatedChart","datamaps", package="rMaps") )
))
关于 Shiny 的 rMaps : Legend and labels are not getting displayed in US choropleth in shiny app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34386982/
以下代码根据层次聚类创建 Choropleth map (使用 hclust() 和 cutree() ): library(plotly) library(cluster) hc %
我想使用plotly和Choroplet根据某些国家的人口流动情况显示世界地图,但它不起作用,我不明白为什么。 This is my pandas table 这段代码应该绘制图表: import p
我昨天问了一个问题,但我猜是代码太多或不清楚,所以我已将其删除,并将尝试使我的问题更清楚。 我有一个包含世界上所有国家/地区的数据框 (df),它看起来像这样: Country CountryCode
我正在使用 Potly Dashboard 构建仪表板。我使用的是深色引导主题,因此我不需要白色背景。 但是,我的 map 现在看起来像这样: 生成它的代码如下所示: trace_map = html
我正在使用 Bostock's Quantile Choropleth 的变体. 我已经成功地缩放了投影并整合了我自己的数据。我目前还在过滤 json 县数据,以仅包括以州 ID 48 开头的县 ID
我尝试按照有关 leaflet 上的图层控件的教程进行操作,但无法使其按我想要的方式运行。我希望有 2 个不同的 choropleth 层可供用户在图层控件中选择,一次显示一个。但是,当我取消选中 h
我正在关注这个例子: http://bl.ocks.org/ElefHead/ebff082d41ef8b9658059c408096f782 但是,我不明白为什么我只画了 3 个东西(县、州、州边界
我根据人口使用传单制作了等值线。 Leaflet 中是否有一个属性假设 5 个地方的人口恰好为 10,然后根本不给它们着色?没有填充之类的东西? 我也无法理解为什么我设置成奶油色的时候还有深蓝色。 这
我正在使用 Bostock's Quantile Choropleth 的变体. 我已经成功缩放了投影并集成了我自己的数据。我目前还在过滤 json 县数据,仅包含以州 ID 48 开头的县 ID。
我正在尝试使用 folium 创建等值线图,按照此处的示例:https://pypi.python.org/pypi/folium .目标是制作美国失业率的等值线图,但当我打开 map 时,美国各州没
我正在尝试使用从此处下载的 geojson 数据文件绘制英国的等值线图:https://data.gov.uk/dataset/regions-december-2016-full-extent-bo
编辑** 这里是一个链接 my website .传单测试一页是目前有效的传单测试页 2 是当我尝试添加交互功能时。 我很难让我的交互式 map 真正具有交互性。我正在绘制宾夕法尼亚州各县水井数量的
我正在努力解决我在使用 folium choropleth map 时遇到的问题。我正在可视化 COVID-19 病例,并尝试根据它们的分位数隶属关系绘制颜色。然而,不幸的是,传说重叠了。因此,我想知
在 R 中,我可以像这样移动阿拉斯加和夏威夷: https://www.storybench.org/how-to-shift-alaska-and-hawaii-below-the-lower-48
我有一个关于 folium 中的 Choropleth 函数的问题。 state_data = pd.read_csv('data.csv') mssp = folium.Map() folium.C
我正在用 geopandas 制作等值线图。我想绘制具有两层边界的 map :较薄的用于民族国家(geopandas 默认),较厚的用于各种经济社区。这在地理 Pandas 中可行吗? 下面是一个例子
我很抱歉,因为我很确定这是一个基本问题。我想要做的就是使用 maps 包在 R 中创建一个非常简单的等值线图。这是我第一次尝试在 R 中映射任何数据。 我的地理位置是包括哥伦比亚特区在内的 48 个州
我有以下 Pandas 数据框 df,如下所示: import pandas as pd df = pd.DataFrame({'state' : ['NY', 'CA', 'FL', 'NJ', '
我想删除 ggplot 中生成的等值线区域之间的线。我的问题是由一张非常大的 map 引起的,其中包含非常非常小的区域(人口普查区 block 组),这些区域数量如此之多,以至于鉴于边界的密度,不可能
我已经在 Folium 中使用 Choropleth 和 Cluster 标记图工作了一段时间(非常棒)。我的问题是是否可以将它们组合在一张图中,这样我就可以看到一个变量对另一个变量的影响有多大。我可
我是一名优秀的程序员,十分优秀!