Creating beautiful charts in chinese with ggplot2
Before we start
My chinese skills are poor and biased. I did learn during my internship and I continue to study while I can translate "last year our exports were 19,000 USD million" but I don't know all the colors.
I will use this dataset and for the example and you can use any chinese font you want. In this example I'm using Adobe Heiti.
Initial setup
These are the necessary libraries and I did read directly from the xlsx file before defining levels, labels and colors.
library(XLConnect)
library(ggplot2)
library(RColorBrewer)
library(scales)
library(plyr)
library(forcats)
file <- paste0(getwd(),"/ggplot2_chinese/trade_data_chile_china.xlsx")
data <- readWorksheetFromFile(file, sheet = "Sheet1", region = "A3:K13", header = TRUE)
data2 <- readWorksheetFromFile(file, sheet = "Sheet1", region = "A17:F27", header = TRUE)
data3 <- readWorksheetFromFile(file, sheet = "Sheet1", region = "A30:C35", header = TRUE)
data4 <- readWorksheetFromFile(file, sheet = "Sheet1", region = "A39:E59", header = TRUE)
data5 <- readWorksheetFromFile(file, sheet = "Sheet1", region = "A62:G72", header = TRUE)
data6 <- readWorksheetFromFile(file, sheet = "Sheet1", region = "A75:C125", header = TRUE)
data <- as.data.frame(data)
data2 <- as.data.frame(data2)
data3 <- as.data.frame(data3)
data3$country <- factor(data3$country, levels = c("china","usa","eu","japan","korea"), labels = c("中国","美国","欧盟","日本","朝鲜"))
data4 <- as.data.frame(data4)
data4$product <- factor(data4$product, levels = c("copper","others"), labels = c("铜","木浆, 水果, 鱒屬和等产品"))
data4 <- ddply(data4, .(year), transform, pos = cumsum(percentage) - (0.5 * percentage))
data4 <- ddply(data4, .(year), transform, pos2 = cumsum(exports) - (0.5 * exports))
data5 <- as.data.frame(data5)
data6 <- as.data.frame(data6)
data6$product <- factor(data6$product, levels=c("fruits", "processedfoods", "bottledwine", "salmon", "forestryandfurniture"), labels=c("水果", "再制", "瓶装酒", "鱒屬",