2
我正在使用空間像素數據框在ggplot中繪製物種預測圖。我的情節幾乎是我想要的,唯一的問題是我的光柵比例從白色變成了紅色,所以很難看到它在傳說see the plot中的起始位置。我想繪製一個框來概述傳說的關鍵 - 只是從白色到紅色的酒吧不再是其餘的酒吧。我一直在尋找一個多小時,但我找不到任何方法來做到這一點,只有這樣才能給圖例添加一個背景或者在圖例文本和圖標周圍繪製一個框,我不想這樣做。有誰知道這是可能做到ggplot或我需要改變我的顏色漸變?圍繞光柵鍵繪製一個框
謝謝!
我的繪製代碼:
ggplot() +
geom_raster(data=habs_pop_clip1, aes(x = easting.x, y = northing.x, fill = pred)) +
scale_fill_gradient("Probability of occurrence", low="white", high="red",limits = c(0,1)) +
coord_fixed(ratio=1, xlim=c(545000, 654000), ylim=c(278000,347000))+
geom_polygon(data=Norfolk1, aes(x=long, y=lat, Group=group), color="grey",fill=NA)+
theme(text = element_text(family = "serif")) +
geom_segment(aes(x = 550000, y = 278500, xend = 560000, yend = 278500), lineend = "round") +
annotate("text", x = 555000, xend = 555000, y = 282000, yend = 282000, label = "10 km", family = "serif", size = 4) +
ggtitle(colnames(bat_occ[i+7])) +
theme(plot.margin=unit(c(0.5, 0.5, 0.5, 0.5), "cm")) +
theme_bw() +
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.line=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.text =element_blank())
驚人!謝謝!這正是我想要的。 –