由于本地 rstudio 和 r ui 中的特定日文字符而无法绘制绘图,但在 rstudio.cloud 中使用 plotly 没有问题
Fail to draw plot because of a specific Japanese character in local rstudio and r ui but no probelm in rstudio.cloud using plotly
无法使用我的 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')
无法使用我的 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')