我从网上取了一个德国的形状图像,并通过https://spotify.github.io/coordinator/将其转换为50个点。
的数据
我也从这个网站获得原始数据,喜欢在R中重新创建德国的点形状。我读取json
数据并获得x和y坐标。
library(jsonlite)
library(tidyverse)
json_string <- '
[[540,332],[525.8673706054688,285.98309326171875],[515.3498840332031,233.10569763183594],[499.3660888671875,188.9991912841797],[490.1600341796875,133.55309295654297],[457.92767333984375,96.12726593017578],[414.88153076171875,74.93893814086914],[370.1520080566406,97.94972229003906],[326.9494934082031,115.06555938720703],[322.642333984375,89.7661361694336],[277.89208984375,82.11088180541992],[260.78253173828125,45.16008186340332],[208.6212615966797,33.503520011901855],[214.01766967773438,70.76221466064453],[205.77508544921875,104.86630249023438],[198.83863830566406,126.0848159790039],[172.58865356445312,150.8688201904297],[157.6624755859375,141.99374389648438],[108.19580078125,156.77096557617188],[111.21473693847656,206.62644958496094],[84.68843841552734,245.4501953125],[90.67401123046875,280.5671081542969],[58.516387939453125,302.04315185546875],[52.970733642578125,344.23388671875],[42.458900451660156,383.45556640625],[57.81577682495117,429.778076171875],[52.560577392578125,480.62005615234375],[64.63249969482422,526.5261535644531],[109.45503234863281,546.9636840820312],[159.35745239257812,563.7278442382812],[130.66680908203125,611.4195556640625],[117.22815704345703,668.0169677734375],[154.635986328125,686.1691284179688],[186.16036987304688,674.2149047851562],[212.90113830566406,672.6448364257812],[263.6999969482422,698.590087890625],[293.43646240234375,691.4788208007812],[346.10491943359375,702.1339111328125],[399.1070861816406,684.85009765625],[443.1532897949219,694.6134643554688],[440.6780090332031,653.3363647460938],[466.5060119628906,614.8057250976562],[490.922119140625,579.669189453125],[451.4901123046875,541.154541015625],[412.4823303222656,503.34405517578125],[389.91070556640625,456.73211669921875],[412.7138366699219,434.9665832519531],[461.1761169433594,413.793701171875],[510.49798583984375,386.5573425292969],[536.9722900390625,386.751953125]]'
parsed_data <- fromJSON(json_string)
df_points <- data.frame(x = parsed_data[, 1], y = parsed_data[, 2])
# Plot the points
ggplot(df_points, aes(x, y)) +
geom_point() +
theme_minimal()
字符串
但是我的图像看起来像是x和y坐标颠倒了。我该如何解决这个问题?
的
2条答案
按热度按时间gcmastyq1#
Ggplot2中的默认坐标系的原点(0,0)位于左下角,而您的数据似乎使用的是原点位于左上角的坐标系,因此使用scale_y_reverse()来反转ggplot中的y轴,以匹配数据的坐标系。
字符串
azpvetkf2#
不是问题的答案,而是如何直接在R中实现。让我们取德国的面积,将其转换为linestring,围绕边界采样并绘制它:
字符串
x1c 0d1x的数据
创建于2024-01-04带有reprex v2.0.2