英文:
Why is the background of my plot black when I use plot_gg() from Rayshader in R
问题
我试图使用Rayshader包在3D中表示某个区域的一些点数据。它正确绘制了一切,只是背景完全是黑色的。如何修复这个问题?以下是我的代码:
base_map <- ggplot(data = df.shp, mapping = aes(x = long, y = lat, group = group)) +
geom_polygon(color = "#8a8a8a", fill = "#8a8a8a") +
coord_quickmap() +
theme_void()
growing_stock = base_map +
geom_point(data = temp1, aes(x=longitude, y=latitude, color=volume_per_ha, group=time),size=2) +
scale_colour_gradient(name = 'Average growing stock [m3/ha]',
limits=range(temp1$volume_per_ha),
low="#FCB9B2", high="#B23A48")
growing_stock
plot_gg(growing_stock, width=5, height=5, multicore = TRUE, scale = 300)
这是绘图的样子。
英文:
I am trying to represent some point data for a region in 3D using the Rayshader package. It plots everything correctly, except that the background is totally black. How to fix this? Below is my code:
base_map <- ggplot(data = df.shp, mapping = aes(x = long, y = lat, group = group)) +
geom_polygon(color = "#8a8a8a", fill = "#8a8a8a") +
coord_quickmap() +
theme_void()
growing_stock = base_map +
geom_point(data = temp1, aes(x=longitude, y=latitude, color=volume_per_ha, group=time),size=2) +
scale_colour_gradient(name = 'Average growing stock [m3/ha]',
limits=range(temp1$volume_per_ha),
low="#FCB9B2", high="#B23A48")
growing_stock
plot_gg(growing_stock, width=5, height=5, multicore = TRUE, scale = 300)
Here is how the plot looks like
答案1
得分: 1
你有几种选项来解决这个问题。删除 theme_void
,或者用其他主题之一替换它可以改变背景颜色,但会向图表中添加一些你可能不想要的 ggplot2
组件。解决问题的一种简单方法就是使用 theme()
明确更改背景颜色。
base_map <- ggplot(data = df.shp, mapping = aes(x = long, y = lat, group = group)) +
geom_polygon(color = "#8a8a8a", fill = "#8a8a8a") +
coord_quickmap() +
theme_void() +
theme(
plot.background = element_rect(
fill = "white",
colour = "white"
)
)
在这个示例中,我将背景颜色更改为 "white"。你可以选择更改为其他颜色。
英文:
You have several options to fix this. Removing theme_void
, or replacing it with one of other themes can change the background color, but will add some other ggplot2
components to the graph that you may not want. One easy way to fix the problem is just to explicitly change the background color using theme()
.
base_map <- ggplot(data = df.shp, mapping = aes(x = long, y = lat, group = group)) +
geom_polygon(color = "#8a8a8a", fill = "#8a8a8a") +
coord_quickmap() +
theme_void() +
theme(
plot.background = element_rect(
fill = "white",
colour = "white"
)
)
I changed background color to "white" in this example. You may want to change to another color.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论