gpt4 book ai didi

r - 很难使用 ggplot2 在图像上排列点

转载 作者:行者123 更新时间:2023-12-04 11:48:15 26 4
gpt4 key购买 nike

我最初尝试使用 geom_rastergeom_tile创建此背景,但转而使用图像,因为我认为它会更容易。

但是,我无法让图像占据整个背景,因此点正确叠加在它上面。背景图片在这里:http://imgur.com/a/eZGAP

它应该是这样的:
enter image description here

但它是这样出来的:
enter image description here

这是一个 dput数据:

structure(list(Industry.Group = c("Defense / Military", "Energy",
"Financial Services", "Healthcare", "Manufacturing", "Public Sector (non-defense) / Not For Profit",
"Retail", "Services", "Technology", "Telecommunications", "Transportation"
), ciq_tech = c(55.9, 53.7111111111111, 60.743661971831, 45.0620689655172,
42.1529411764706, 52.2444444444444, 40.8, 52.3263157894737, 50.9222222222222,
59.5111111111111, 39.6666666666667), Industry.Group = c("Defense / Military",
"Energy", "Financial Services", "Healthcare", "Manufacturing",
"Public Sector (non-defense) / Not For Profit", "Retail", "Services",
"Technology", "Telecommunications", "Transportation"), ciq_org = c(39.6666666666667,
48.7413636363636, 48.0868442622951, 42.2482222222222, 39.0128260869565,
38.482, 39.7786956521739, 41.7248387096774, 47.8644262295082,
49.6739285714286, 41.4825)), .Names = c("Industry.Group", "ciq_tech",
"Industry.Group", "ciq_org"), row.names = c(NA, -11L), class = "data.frame")

我已经试过了,并且一直在调整 xmin , xmaxyminymax变量:

library(png)
library(grid)
library(ggplot2)
img <- readPNG("grid.png")
g <- rasterGrob(img, interpolate=TRUE)

ggplot(both, aes(x = ciq_org, y = ciq_tech)) +
theme_bw() + annotation_custom(g, xmin=31, xmax=57, ymin=38, ymax=61) + geom_point()

也:
ggplot(both, aes(x = ciq_org, y = ciq_tech))  +
theme_bw() + annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + geom_point()

我也愿意使用 geom_raster相反,如果在 ggplot2 中使用本地固定方块和颜色重新创建背景会更容易。

最佳答案

你可以试试这个:

ggplot(both, aes(x = ciq_org, y = ciq_tech))  +
theme_bw() + annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_point(size=5, col='steelblue') +
xlim(c(31, 57)) +
ylim(c(38,61)) +
theme_void()

enter image description here

关于r - 很难使用 ggplot2 在图像上排列点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42096961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com