Wednesday, December 20, 2017

在mac下使用ggplot2画图的中文显示问题

library(readr)
segsimcat <- read_delim("~/segsimcat.txt",
                        "\t", escape_double = FALSE, trim_ws = TRUE)
View(segsimcat)


colnames(segsimcat)
library(ggplot2)
library(dplyr)
unique(segsimcat$name)
ggplot(filter(segsimcat,name=="美食"), aes(sim)) +
  geom_histogram(bins = 100)

ggplot(segsimcat, aes(sim, colour = name)) +
  geom_freqpoly(bins = 100)+theme(text = element_text(family = "STHeiti"))
# binwidth = 500
ggplot(segsimcat, aes(sim, fill = name)) +
  geom_histogram(bins = 100)+theme(text = element_text(family = "STHeiti"))


for(x in unique(segsimcat$name)){
print(ggplot(filter(segsimcat,name==x), aes(sim)) +
  geom_histogram(bins = 100)+ggtitle(x)+theme(text = element_text(family = "STHeiti"))
  )}



中文显示问题 http://not.farbox.com/post/chinese-character-font-mac-rlan


rmarkdown 到pdf的中文问题:
https://github.com/yixuan/showtext
https://statr.me/2014/01/using-system-fonts-in-r-graphs/

No comments:

Post a Comment