Closed JiaxiangBU closed 5 years ago
老哥,你可以用theme_ipsum(base_family = "包含中文的字体"),这样就行了
我尝试了,依然是报错的。
library(hrbrthemes)
#> Warning: 程辑包'hrbrthemes'是用R版本3.5.2 来建造的
#> NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
#> Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
#> if Arial Narrow is not on your system, please see http://bit.ly/arialnarrow
library(gcookbook)
library(tidyverse)
# current verison
packageVersion("hrbrthemes")
#> [1] '0.6.0'
Created on 2019-02-06 by the reprex package (v0.2.1)
p <-
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
labs(x="燃油效率", y="重量,单位吨",
title="散点图例子",
subtitle="就是用用中文而已",
caption="数据来自tidyverse, mtcars")
p + theme_ipsum()
p + theme_ipsum(base_family = "STKaiti")
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : 找不到多边形的边
这个指定的字体我也是有的,如图。
老哥,你的例子我尝试了,没有出错,你把绘图窗口调大点试试呗:
library(hrbrthemes)
library(gcookbook)
library(tidyverse)
packageVersion("hrbrthemes")
p <-
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
labs(x="燃油效率", y="重量,单位吨",
title="散点图例子",
subtitle="就是用用中文而已",
caption="数据来自tidyverse, mtcars")
p + theme_ipsum()
p + theme_ipsum(base_family = "STKaiti")
@czxa 我把窗口放大到这个程度也不行,感觉是我电脑配置的问题了。
@JiaxiangBU 是不是因为你的R版本过老呢?要不你升级一下R的版本再试试。
@JiaxiangBU 我的R版本信息是:
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.3
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.5/Resources/lib/libRlapack.dylib
locale:
[1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/en_US.UTF-8/zh_CN.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] mathpix_0.3.0 reshape2_1.4.3 RColorBrewer_1.1-2
[4] dplyr_0.7.8 ggplot2_3.1.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 rstudioapi_0.9.0 bindr_0.1.1
[4] magrittr_1.5 tidyselect_0.2.5 munsell_0.5.0
[7] colorspace_1.4-0 R6_2.3.0 rlang_0.3.1
[10] httr_1.4.0 stringr_1.4.0 plyr_1.8.4
[13] tools_3.5.2 grid_3.5.2 gtable_0.2.0
[16] withr_2.1.2 lazyeval_0.2.1 assertthat_0.2.0
[19] tibble_2.0.1 crayon_1.3.4 bindrcpp_0.2.2
[22] purrr_0.3.0 base64enc_0.1-3 curl_3.3
[25] glue_1.3.0 stringi_1.2.4 compiler_3.5.2
[28] pillar_1.3.1 scales_1.0.0 jsonlite_1.6
[31] pkgconfig_2.0.2
我的R不是最新的,那我升级下看看。
"session info"
#> [1] "session info"
Created on 2019-02-12 by the reprex package (v0.2.1)
library(hrbrthemes)
#> NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
#> Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
#> if Arial Narrow is not on your system, please see http://bit.ly/arialnarrow
library(ggplot2)
p <-
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
labs(x="燃油效率", y="重量,单位吨",
title="散点图例子",
subtitle="就是用用中文而已",
caption="数据来自tidyverse, mtcars")
p + theme_ipsum()
p + theme_ipsum(base_family = "STKaiti")
Created on 2019-04-20 by the reprex package (v0.2.1)
theme(text = element_text(family = "STKaiti"))
is a way to show Chinese font on the plot. I find it cannot work with functiontheme_ipsum()
.But for other ggplot theme, like
theme_minimal()
, this way works well.Here is my
sessionInfo()