gpt4 book ai didi

R ggplot2 hexbin 绘图图形错误?

转载 作者:行者123 更新时间:2023-12-05 07:11:46 41 4
gpt4 key购买 nike

我总是发现一些奇怪的白色水平虚线,这些虚线似乎出现在我在 R 环境中使用 ggplot2 创建的每个 hexbin 密度图上的垂直相邻六边形之间的边界上。他们当然不属于那里......这种行为(错误)可以在具有不同 MS Windows 版本和不同图形驱动程序的不同计算机上的多个 R 安装中重现。我不知道如何摆脱这些虚线。下面是显示问题的图表,以及生成该图表的代码。这是一个已知问题吗?有什么提示可以克服这个问题吗?非常感谢您的帮助!

Plot with bespoke bug

## Load libraries
library(ggplot2)
library(hexbin)

## Create some data
set.seed(222)
myx <- data.frame(x = 0.4 + rnorm(10000, mean = 0, sd = 0.1))
myy <- data.frame(y = 0.5 + rnorm(10000, mean = 0, sd = 0.1))
MyData <- data.frame(xvariable=myx$x*100, yvariable=myy$y*100)

## Prepare the plot window
dev.off(2)
windows.options(width=6, height=6)
op <- par(mfrow = c(1,1))
op <- par(oma = c(0,0,0,0) + 0.1,
mar = c(5.1, 5.1, 4.1, 2.1))

## Creaate the plot
ggplot(MyData, aes(x=xvariable, y=yvariable) ) +
geom_hex(bins=66) +
xlim(0, 100) +
ylim(0, 100) +
ggtitle("My plot") +
scale_fill_continuous(type = "viridis") +
theme_bw() +
theme(plot.title = element_text(color="black", size=17, face="bold"),
axis.title.x = element_text(color="black", size=17, face="bold"),
axis.title.y = element_text(color="black", size=17, face="bold"),
axis.text=element_text(color="black", size=15, face="bold"),
legend.title = element_text(color = "black", size = 15),
legend.text = element_text(color = "black", size=12),
legend.position = c(0.9,0.2), legend.direction = "vertical")

最佳答案

看起来如果你保存为 pdf 然后将其转换为图像,就不会有线。

enter image description here

关于R ggplot2 hexbin 绘图图形错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60640484/

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