无法绘制绘图,因为本地rstudio和r ui中存在特定的日语字符,但使用plotly在rstudio.cloud中没有问题

无法绘制绘图,因为本地rstudio和r ui中存在特定的日语字符,但使用plotly在rstudio.cloud中没有问题,r,rstudio,plotly,R,Rstudio,Plotly,无法使用my rstudio和Rui显示绘图(查看器中为空白),代码为: 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(日语,to=“UTF-8

无法使用my rstudio和Rui显示绘图(查看器中为空白),代码为:

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(日语,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')

a这在我的本地RStudio(RStudio版本1.2.1578,r3.6.0 Beta)中似乎运行良好。也许可以尝试运行一个新的R会话?在我的环境中,我可以重现这个问题。我认为它发生在windows操作系统(CP932 env)上。这是有道理的,我在Ubuntu 18.04上运行它
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')