R中的Hive瓷砖贴图[已关闭]

xpcnnkqh  于 2023-09-27  发布在  Hive
关注(0)|答案(1)|浏览(134)

已关闭,此问题需要details or clarity。它目前不接受回答。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。

13天前关闭
Improve this question
如何使用RAmCharts包(或其他看起来不错的包)在R中实现这个Hive状图块贴图?
https://www.amcharts.com/demos/honeycomb-tile-map/

t98cgbkg

t98cgbkg1#

用R语言再现这个图形是很容易的

library(tidyverse)

p <- states %>%
  rowwise() %>%
  reframe(x = c(-1, 0, 1, 1, 0, -1, -1) * 0.5 + x,
          y = c(0.25, 0.5, 0.25, -0.25, -0.5, -0.25, 0.25) * 2/sqrt(3) + y, 
          short, name, value) %>%
  ggplot(aes(x, y, fill = value, group = name)) +
  geom_polygon(linewidth = 2, color = "white") +
  geom_text(aes(label = short), data = states) +
  scale_fill_gradient(low = "#fffb77", high = "red", guide = "none") +
  coord_equal() +
  theme_void()

p

您可以使用plotly::ggplotly(p)轻松地将其转换为交互式绘图。
困难的部分是获取数据。我从链接页面上的JavaScript对象中提取了这个,并将其适当地转换为在R中使用:

states <- structure(list(short = c("AL", "AK", "AZ", "AR", "CA", "CO", 
"CT", "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", 
"KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", 
"NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", 
"RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", 
"WY"), name = c("Alabama", "Alaska", "Arizona", "Arkansas", "California", 
"Colorado", "Connecticut", "Delaware", "District of Columbia", 
"Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", 
"Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", 
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", 
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", 
"New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", 
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", 
"South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", 
"Washington", "West Virginia", "Wisconsin", "Wyoming"), y = c(-5.19615242270663, 
0, -4.33012701892219, -4.33012701892219, -4.33012701892219, -3.46410161513775, 
-2.59807621135332, -3.46410161513775, -3.46410161513775, -6.92820323027551, 
-6.06217782649107, -6.92820323027551, -2.59807621135332, -2.59807621135332, 
-2.59807621135332, -2.59807621135332, -4.33012701892219, -3.46410161513775, 
-5.19615242270663, 0, -3.46410161513775, -1.73205080756888, -1.73205080756888, 
-1.73205080756888, -5.19615242270663, -3.46410161513775, -1.73205080756888, 
-3.46410161513775, -3.46410161513775, -0.866025403784439, -2.59807621135332, 
-5.19615242270663, -1.73205080756888, -4.33012701892219, -1.73205080756888, 
-2.59807621135332, -5.19615242270663, -3.46410161513775, -2.59807621135332, 
-1.73205080756888, -5.19615242270663, -2.59807621135332, -4.33012701892219, 
-6.06217782649107, -4.33012701892219, -0.866025403784439, -4.33012701892219, 
-1.73205080756888, -3.46410161513775, -1.73205080756888, -2.59807621135332
), x = c(7.5, 0.5, 3, 6, 2, 3.5, 11, 9.5, 10.5, 8.5, 8, 0.5, 
2, 6, 7, 5, 5, 6.5, 5.5, 11.5, 8.5, 10.5, 7.5, 4.5, 6.5, 5.5, 
2.5, 4.5, 2.5, 11, 10, 3.5, 9.5, 9, 3.5, 8, 4.5, 1.5, 9, 11.5, 
8.5, 4, 7, 4, 4, 10, 8, 1.5, 7.5, 5.5, 3), value = c(4849300L, 
737700L, 6745400L, 2994000L, 39250000L, 5540500L, 3596600L, 935600L, 
7288000L, 20612400L, 10310300L, 1419500L, 1634400L, 12801500L, 
6596800L, 3107100L, 2904000L, 4413400L, 4649600L, 1330000L, 6016400L, 
6811700L, 9928300L, 5519900L, 2984900L, 6093000L, 1023500L, 1881500L, 
2839000L, 1326800L, 8944400L, 2085500L, 19745200L, 10146700L, 
739400L, 11614370L, 3878000L, 3970200L, 12784200L, 1055100L, 
4832400L, 853100L, 6651100L, 27862500L, 2942900L, 626010L, 8411800L, 
7288000L, 1850320L, 5778700L, 584150L)), class = "data.frame", row.names = c(NA, 
51L))

相关问题