R plots with X11 cannot show CJK fonts -
i loaded utf-8 csv file japanese characters in it, str this:
> str(purchases) 'data.frame': 168996 obs. of 7 variables: $ item_count : int 1 1 1 1 1 1 2 2 1 1 ... $ i_date : date, format: "2012-03-28" "2011-07-04" ... $ small_area_name: factor w/ 55 levels "キタ","ミナミ他",..: 6 47 26 26 26 26 26 35 35 26 ... $ user_id_hash : factor w/ 22782 levels "0000b53e182165208887ba65c079fc21",..: 19467 7623 7623 7623 7623 7623 7623 7623 7623 7623 ... $ coupon_id_hash : factor w/ 19368 levels "000eba9b783cec10658308b5836349f6",..: 3929 8983 5982 5982 5982 5982 5982 2737 18489 5018 ... $ category : factor w/ 13 levels "beauty","delivery service",..: 2 3 2 2 2 2 2 7 2 3 ...
so think there's nothing wrong encoding or locale(en_us.utf-8)? when plot with
> barplot(table(purchases$small_area_name))
why japanese characters turn little blocks this?
i think have font display japanese characters
> names(x11fonts()) [1] "serif" "sans" "mono" "times" "helvetica" [6] "cyrtimes" "cyrhelvetica" "arial" "mincho"
additional info:
> sessioninfo() r version 3.2.2 (2015-08-14) platform: x86_64-apple-darwin13.4.0 (64-bit) running under: os x 10.10.5 (yosemite) 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] ggplot2_1.0.1
you may want take @ showtext package, allows use different fonts in r graphs. ships cjk font can used directly.
try run code below:
library(showtext) showtext.auto() ## ... code generate data barplot(table(purchases$small_area_name))
Comments
Post a Comment