【发布时间】:2019-04-25 05:40:41
【问题描述】:
我正在使用 geom_path 在海岸线地图上绘制数据,但我无法删除连接第一个和最后一个数据点的线。这方面的数据集相当大,但可以找到here。
问题已在this thread 上报告并修复,但对我的情况没有帮助。
LHplot <- ggplot(data = LH, aes(x = long, y = lat, group=group)) +
geom_path(aes(group=group), size = 1, color = "darkgrey") +
theme_bw() +
theme(axis.line.y=element_blank(),
axis.line.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid.major = element_blank(), # switch off major gridlines
panel.grid.minor = element_blank(), # switch off minor gridlines
panel.border = element_blank(),
text=element_text(family="Times New Roman", size=11)
)
LHplot
我还注意到,在绘制数据子集时,路径可能打开也可能不打开
LH2 <- LH[1:16000,]
LH2plot <- ggplot(data = LH2, aes(x = long, y = lat, group=group)) +
geom_path(aes(group=group), size = 1, color = "darkgrey") +
theme_bw() +
theme(axis.line.y=element_blank(),
axis.line.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid.major = element_blank(), # switch off major gridlines
panel.grid.minor = element_blank(), # switch off minor gridlines
panel.border = element_blank(),
text=element_text(family="Times New Roman", size=11)
)
LH2plot
LH2 <- LH[1:50000,]
LH2plot <- ggplot(data = LH2, aes(x = long, y = lat, group=group)) +
geom_path(aes(group=group), size = 1, color = "darkgrey") +
theme_bw() +
theme(axis.line.y=element_blank(),
axis.line.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid.major = element_blank(), # switch off major gridlines
panel.grid.minor = element_blank(), # switch off minor gridlines
panel.border = element_blank(),
text=element_text(family="Times New Roman", size=11)
)
LH2plot
问题是否来自数据集中的空白?或者只是它在数据框中的组织方式以及 geom_path 是如何读取它的?
编辑
来自下面的评论:我按纬度对数据进行排序以绘制从南到北的路径:
LH <- LH[order(LH$lat),]
【问题讨论】:
-
我认为这正是它订购的方式。
geom_path将根据 data.frame 行中显示的顺序绘制它们。我不认为group应该在这里起到任何作用,因为您正在生产一个线段。如果可能的话,我会设置从国家草图开始到结束的行顺序,然后使用不带组的 geom_path。应该可以正常工作 -
问题是你的大陆组不是从南开始到北结束,而是从特隆赫姆以北开始,在北边,然后从南边开始。
-
@JonnyPhelps
group将把岛屿与大陆分开 -
啊对,我还以为只有一行,我错了
-
@RichardTelford 你说得对,地理区域做得好!我确实对我的数据进行了排序,但似乎我对峡湾有问题,如编辑中所示。我会试试你的答案。