r - mac上的扭曲线(带有非实线型)ggplot

标签 r macos ggplot2

第一次海报在这里。我希望我做对了。我遇到以下问题已有一段时间了,我真的很想了解出了什么问题。

我正在尝试用 ggplot 绘制一条虚线。

x = c(1:405)
y = c(rep(0,135),seq(1:135),rep(135,135))

ggplot() + geom_line(aes(x, y),linetype = 2, size=1)

然而,虚线出现扭曲。线条不是均匀分布的。这既发生在 R 的绘图窗口中,也发生在我用 ggsave 保存绘图时。当我改变绘图窗口的大小时,失真会发生变化,但它通常发生在 x = 100、200 和/或 300 附近。它在 R 和 Rstudio 中都发生。我正在使用 Mac 将所有内容都更新到最新版本。当我的同事在 linux 中绘制同一行时,他没有问题。

扭曲的虚线

enter image description here

这是 session 信息:
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] data.table_1.12.8 gtools_3.8.1      Rcpp_1.0.3        svMisc_1.1.0      cowplot_1.0.0     dplyr_0.8.3       zoo_1.8-6         car_3.0-5         carData_3.0-3    
[10] ggplot2_3.2.1     lmerTest_3.1-1    lme4_1.1-21       Matrix_1.2-18    

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5    purrr_0.3.3         splines_3.6.2       haven_2.2.0         lattice_0.20-38     colorspace_1.4-1    vctrs_0.2.1         utf8_1.1.4         
 [9] rlang_0.4.2         nloptr_1.2.1        pillar_1.4.2        foreign_0.8-72      glue_1.3.1          withr_2.1.2         readxl_1.3.1        lifecycle_0.1.0    
[17] munsell_0.5.0       gtable_0.3.0        cellranger_1.1.0    zip_2.0.4           labeling_0.3        rio_0.5.16          forcats_0.4.0       curl_4.3           
[25] fansi_0.4.0         scales_1.1.0        backports_1.1.5     abind_1.4-5         farver_2.0.1        hms_0.5.2           digest_0.6.23       stringi_1.4.3      
[33] openxlsx_4.1.4      numDeriv_2016.8-1.1 grid_3.6.2          cli_2.0.0           tools_3.6.2         magrittr_1.5        lazyeval_0.2.2      tibble_2.1.3       
[41] crayon_1.3.4        pkgconfig_2.0.3     zeallot_0.1.0       MASS_7.3-51.4       assertthat_0.2.1    minqa_1.2.4         rstudioapi_0.10     R6_2.4.1           
[49] boot_1.3-23         nlme_3.1-142        compiler_3.6.2    

有谁知道可能是什么问题?

最佳答案

它没有解释为什么会发生,而是使用 Cairographicsggsave修复问题(见 here):

library(ggplot2)
library(Cairo)

x = c(1:405)
y = c(rep(0,135),seq(1:135),rep(135,135))

gg <- ggplot() + geom_line(aes(x, y),linetype = 2, size=1)
ggsave("plot.png", gg, type="cairo-png")

关于r - mac上的扭曲线(带有非实线型)ggplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59785085/

相关文章:

javascript - 通过js设置R Shiny 的默认textInput值(作为js函数的结果)

r - 如何从 R 数据框中过滤唯一的列组合

r - 如何在R中绘制不同颜色和形状的单线?

html - Mac 和 Windows 环境下的 Google Chrome 浏览器 for input type=range

r - 以定义的方式排列图例中的项目

r - 如何创建一个用不等距矩阵图覆盖点数据的图?

在 R 中保留之前的日期

r - 每个变量具有多列的分组频率表

ios - 是否有 GCD 等同于设置可以取消并在以后重新安排的计时器?

python - 导入 lxml 在(看似)成功安装后在 OSX 上失败