Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 变形线(非实线型)在mac上绘制_R_Macos_Ggplot2 - Fatal编程技术网

R 变形线(非实线型)在mac上绘制

R 变形线(非实线型)在mac上绘制,r,macos,ggplot2,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保存绘图时。当我改变绘图窗口的大小时,失真会发生变化,但通常发生

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

我试图用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上绘制同一条线时,他没有任何问题

扭曲虚线

这是sessionInfo:

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    

有人知道可能是什么问题吗?

它没有解释为什么会发生这种情况,但使用
Cairographics
ggsave
解决了这个问题(请参阅):

库(ggplot2)
图书馆(开罗)
x=c(1:405)
y=c(代表(0135),序号(1:135),代表(135135))

同样的事情也发生在我的Mac上。您能否将您的
sessionInfo()
添加到您的问题中,以便其他人可能知道您的确切R和OS配置。使用
Cairographics
ggsave
似乎可以解决我的问题(请参阅):
ggsave(“plot.png”,myplot,type=“cairo png”)
@Romain谢谢,这确实也解决了我的问题。很好,我把它作为一个有趣的矢量问题。我个人认为最好是以pdf格式输出,这样我就可以将绘图以我想要的任何分辨率保存在任何期刊要求的任何文件格式中,而无需重新安排所有内容。(注意:Dingbats.
useDingbats
选项对于“怪异的矢量化”也很重要)。
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")