我对R上的地图可视化非常陌生,而我试图在动作等级中改变传说。
我的代码在
ds <- a21 %>%
group_by(fips) %>%
do(item = list(
fips = first(.$fips),
sequence = .$freq,
value = first(.$freq))) %>%
.$item
hc <- highchart(type = "map") %>%
hc_add_series(data = ds,
name = "complaints",
mapData = uscountygeojson,
joinBy = "fips",
borderWidth = 0.01) %>%
hc_colorAxis(stops = color_stops()) %>%
hc_title(text = "patient complaints") %>%
hc_legend(layout = "vertical", reversed = TRUE,
floating = TRUE, align = "right") %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_motion(
enabled = TRUE,
axisLabel = "year",
labels = sort(unique(a21$year)),
series = 0,
updateIterval = 50,
magnet = list(
round = "floor",
step = 0.1
)
)
现有结果的屏幕截图:
截至目前,我看到R会自动创建频率色块
我希望在我的数据框中将其更改为一组自定义值。
我的数据框的片段在
下面a21:
year fips freq q
1 2004 1001 3 1st Quantile
2 2005 1001 0 1st Quantile
3 2006 1001 4 1st Quantile
4 2007 1001 0 1st Quantile
5 2008 1001 0 1st Quantile
6 2009 1001 0 1st Quantile
我想将列q作为颜色轴标签
答案 0 :(得分:0)
我认为您需要将列q与颜色关联(可能是数据框中的另一列),然后将这些颜色与color_stops函数结合使用。
例如:
library(dplyr)
library(highcharter)
mapdata <- get_data_from_map(download_map_data("countries/us/us-all"))
set.seed(1234)
data_fake <- mapdata %>%
select(code = `hc-a2`) %>%
mutate(value = 1e5 * abs(rt(nrow(.), df = 10)))
colors <- c("red", "blue", "green" , "yellow")
hcmap("countries/us/us-all", data = data_fake, value = "value",
joinBy = c("hc-a2", "code"), name = "Fake data",
dataLabels = list(enabled = TRUE, format = '{point.name}'),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueDecimals = 2, valuePrefix = "$", valueSuffix =
"USD"))%>%
hc_colorAxis(minColor = "blue", maxColor = "red",
stops = color_stops(n=length(colors), colors = colors))