简体   繁体   English

R ggplotly生成正确的图,但是当移动到plot.ly时,x轴不同

[英]R ggplotly producing correct plot, but when moving to plot.ly, x-axis is different

Producing a plotly object using ggplotly returns exactly what I need, however, when using api_create() and pushing the object to plotly online, the x-axis appears as numeric, and not a factor as I declared it to be in R. 使用ggplotly生产一个plotly对象将返回我真正需要的东西,但是,当使用api_create()并将该对象推到plotly在线时,x轴显示为数字,而不是我声明为R的因子。

mem$Office <- as.factor(mem$Office)
mem_plot <- ggplot(data=mem,aes(x=Office,y=Total, fill=Office)) + 
geom_bar(size=mem$Total,width=0.5,position='dodge',stat='identity') + 
labs(x = 'Office', y = 'Total')

mem_plot <- ggplotly(mem_plot,tooltip=c("x","y"))

mem_plot 

Which returns: 哪个返回: 在此处输入图片说明

Then I run: api_create(mem_plot, filename = "memership-plot") 然后我运行: api_create(mem_plot, filename = "memership-plot")

And get this from plot.ly: 并从plot.ly获取: 在此处输入图片说明

需要调整ggplotly()命令。

mem_plot <- ggplotly(mem_plot, dynamicTicks = T)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM