我试图在R图中显示国际象棋符号。我在互联网上搜索了很多,但我找不到答案。
symbols <- data.frame(c(1,2,3,4,5,6,7,8),c(2,2,2,2,2,2,2,2),rep("\U2654", times=8))
symbols_w <- data.frame(c(1,2,3,4,5,6,7,8),c(7,7,7,7,7,7,7,7),rep("\U25a0", times=8))
colnames(symbols) <-c("xPos", "yPos", "unicode")
colnames(symbols_w) <-c("xPos", "yPos", "unicode")
symbols$unicode <- as.character(symbols$unicode)
symbols_w$unicode <- as.character(symbols_w$unicode)
chess_field +
geom_text(data = symbols, aes(x=xPos, y=yPos, label=unicode), size = 11, color = "gray20", alpha = 0.7) +
geom_text(data = symbols_w, aes(x=xPos, y=yPos, label=unicode), size = 11, color = "white", alpha = 0.7)
我从这里获取国际象棋人物的Unicode:https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode
它没有正确显示,也许你可以帮助我?
修改
unicode <- rchess:::.chesspiecedata() %>% select(unicode)
uni <- as.character(unicode[1,])
symbols <- data.frame(c(1,2,3,4,5,6,7,8),c(2,2,2,2,2,2,2,2),rep(uni, times=8))
编辑2
dfboard <- rchess:::.chessboarddata() %>% select(cell, col, row, x, y, cc)
chess_field <- ggplot() + geom_tile(data = dfboard, aes(x, y, fill = cc)) +
scale_fill_manual("legend", values = c("chocolate4", "wheat1")) +
scale_x_continuous(breaks = 1:8, labels = letters[1:8]) +
scale_y_continuous(breaks = 1:8, labels = 1:8)
这是棋盘的创建方式。如果我添加了行+主题(text = element_text(family =&#34; Arial Unicode MS&#34;)),我得到一个错误&#34;无效的字体类型&#34; ... grid.call中的错误。 graphics(L_text,ad.graphicsAnnot(x $ label),x $ x,x $ y
我认为这不会那么难,包括这花了我4个小时,只是为了一些Unicode符号..