我正在尝试重现annotation_logticks {ggplot2}的一个例子:
library(ggplot2)
library(MASS)
library(scales)
a <- ggplot(Animals, aes(x = body, y = brain)) + geom_point() +
scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
theme_bw()
a + annotation_logticks()
但是图形输出的刻度不在绘图区域
知道如何解决这个问题?
sessionInfo()信息如下:
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252
attached base packages:
[1] splines grid stats graphics grDevices utils datasets methods
[9] base
other attached packages:
[1] ggtern_1.0.6.0 scales_0.3.0 MASS_7.3-44
[4] colorspace_1.2-6 data.table_1.9.6 reshape2_1.4.1
[7] car_2.1-0 dplyr_0.4.3.9000 xtable_1.7-4
[10] Hmisc_3.16-0 Formula_1.2-1 survival_2.38-3
[13] lattice_0.20-33 Rcpp_0.12.1 gridExtra_2.0.0
[16] micromap_1.9.2 RColorBrewer_1.1-2 maps_2.3-11
[19] raster_2.4-20 spatstat_1.42-2 spdep_0.5-88
[22] Matrix_1.2-2 maptools_0.8-36 rgdal_1.0-7
[25] sp_1.2-0 rgeos_0.3-12 gtable_0.1.2
[28] FactoMineR_1.31.3 RCurl_1.95-4.7 bitops_1.0-6
[31] bit64_0.9-5 bit_1.1-12 minpack.lm_1.1-9
[34] xlsx_0.5.7 xlsxjars_0.6.1 rJava_0.9-7
[37] stringr_1.0.0 prettyR_2.1-1 ggthemes_2.2.1
[40] ggplot2_1.0.1 directlabels_2013.6.15 quadprog_1.5-5
[43] plyr_1.8.3
loaded via a namespace (and not attached):
[1] assertthat_0.1 latticeExtra_0.6-26 LearnBayes_2.15 quantreg_5.19
[5] chron_2.3-47 digest_0.6.8 polyclip_1.3-2 minqa_1.2.4
[9] SparseM_1.7 tensor_1.5 lme4_1.1-9 MatrixModels_0.4-1
[13] mgcv_1.8-7 nnet_7.3-11 pbkrtest_0.4-2 proto_0.3-10
[17] magrittr_1.5 deldir_0.1-9 nlme_3.1-122 foreign_0.8-66
[21] tools_3.2.2 munsell_0.4.2 cluster_2.0.3 flashClust_1.01-2
[25] nloptr_1.0.4 goftest_1.0-3 leaps_2.9 boot_1.3-17
[29] abind_1.4-3 DBI_0.3.1 R6_2.1.1 stringi_0.5-5
[33] parallel_3.2.2 rpart_4.1-10 acepack_1.3-3.3 scatterplot3d_0.3-36
[37] coda_0.17-1
我在没有加载ggtern库的情况下运行代码,问题消失了。但我必须用ggtern做一些其他的图形,我不想开始另一个会话
答案 0 :(得分:0)
即使加载了ggtern,我也找到了解决方案:
library(ggtern)
library(ggplot2)
library(MASS)
library(scales)
a <- ggplot(Animals, aes(x = body, y = brain)) + geom_point() +
scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
theme_bw() + annotation_logticks()
library(grid)
grid.draw(ggplotGrob(a))
如果我不需要ggtern,解决方案显然是运行代码而不加载ggtern库。