我想為幾個點創建一個由箭頭顯示的風向圖。
該圖應該沒有圖例和背景,因為我想將其匯出為 png 并將其用作進一步作業流程中的疊加層。
我有一個示例資料名,有 10 個點(經度、緯度)和風向(以度為單位)。
目前我的情節是這樣的:

我想:
將繪圖擴展到
3.604383、14.60482、47.07157、54.73807(xmin、xmax、ymin、ymax)
和
- 洗掉軸和背景,以便我可以將其匯出為 png 或 tiff 或僅顯示箭頭的柵格。
這是我目前的方法:
library(ggplot)
wind_data<-
structure(list(lon = c(8.87312091729266, 8.71871388830953, 10.5679127453358,
10.7216122406487, 10.4141464047873, 10.5679127453358, 10.1064188710028,
11.3357135330171, 11.4890576651767, 11.1822955254471), lat = c(54.6482360923283,
54.5584019137964, 54.2888913181823, 54.2888913181823, 54.1990517614177,
54.1990517614177, 54.0193686018903, 53.6599860593553, 53.6599860593553,
53.5701370357575), dd = c(238, 235, 238, 232, 232, 236, 239,
240, 240, 240)), class = "data.frame", row.names = c(NA, -10L
p<-ggplot(wind_data, aes(x = lon, y = lat))
geom_segment(aes(xend = lon 0.08, yend = lat 0.08),
arrow = arrow(length = unit(0.1, "cm")), size = 0.25) # Make the line segments 0.25 mm thick
p theme_bw() theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),legend.position="none")
我試圖通過使用來設定情節的大小
coord_cartesian(xlim = c(3.604383, 14.60482), ylim = ( 47.07157, 54.73807 ))
并洗掉圖例
legend.position="none"
但它似乎不起作用。
uj5u.com熱心網友回復:
除了在調整限制和主題選項后不重新分配給變數的問題之外,擺脫所有非資料墨水的快速簡便的方法是使用theme_void()而不是一個一個地洗掉主題元素。但是,必須知道這樣做也會洗掉例如繪圖邊緣。但是,如果需要將它們重新添加回來,仍然可以通過使用例如 theme(plot.margin = margin(5.5, 5.5, 5.5, 5.5, unit = "pt"))默認邊距輕松實作。
library(ggplot2)
p <- ggplot(wind_data, aes(x = lon, y = lat))
geom_segment(aes(xend = lon 0.08, yend = lat 0.08),
arrow = arrow(length = unit(0.1, "cm")), size = 0.25
)
coord_cartesian(xlim = c(3.604383, 14.60482), ylim = c( 47.07157, 54.73807 ))
theme_void()
p

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/523473.html
標籤:rggplot2光栅
上一篇:是否可以以生成的柵格物件代表ggplot的方式柵格化ggplot?
下一篇:通過對行分組的資料線圖
