r - 由于本地 rstudio 和 r ui 中的特定日语字符而无法绘制绘图,但使用 plotly 在 rstudio.cloud 中没有问题
问题描述
无法用我的 rstudio 和 Rui 用代码显示情节(查看器中的空白):
a <- c("予約","リスト")
b <- c(20,30)
df <- data.frame(a,b)
plot_ly(df, x = ~a, y = ~b,type = 'bar')
但是使用相同的代码,该图可以在 rstudio.cloud 中正确显示。当我在下面删除字符“予”时a
,可以正确显示情节。
a <- c("約","リスト")
b <- c(20,30)
df <- data.frame(a,b)
plot_ly(df, x = ~a, y = ~b,type = 'bar')
我将 R 版本更改为 3.6.0(rstudio.cloud 的当前版本)但仍然无法显示。
rstudio version: 1.2.5001
先感谢您。
解决方案
据我所知,这是一个编码问题。
iconv(Japanese, to = "UTF-8")
可以解决。
a <- c("予約","リスト")
b <- c(20, 30)
df <- data.frame(a, b)
plot_ly(df, x = ~ iconv(a, to = "UTF-8"), y = ~ b, type = 'bar')
# or
df2 <- data.frame(a, b, stringsAsFactors = FALSE) %>%
mutate(a = iconv(a, to = "UTF-8"))
plot_ly(df2, x = ~ a, y = ~ b, type = 'bar')
推荐阅读
- php - 如何在 PHP 中将数组转换为键值对
- react-native - Uber H3 geoToH3 在 React Native 中不起作用
- postgresql - 在 PostgreSQL 中获取复杂的交叉销售细节
- javascript - 我想要创建一些目录的指导
- python - Python中的音频文件不播放
- awk - 文件上的 awk 条件,同时保留第一行
- mysql - 来自不同查询的联合值合二为一
- c++ - 在使用 CodeBlock 的 WxSmith gui 编程中将布局添加到 wxPanel 后程序崩溃
- memory - ESP32:经常存储数据的最佳方式?
- javascript - 防止用户单击按钮,直到服务响应角 7 rxjs