本文介绍了取消选择变量时,条形图会“显示" *“苍蝇"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了ggplot2和plotly的一些问题.当使用ggplot2创建条形图并将其传递到函数 ggplotly 时,取消选择变量时,条形图处于半空中.该图的行为不如示例

我在以下位置运行

:

 >sessionInfo()R版本3.3.2(2016-10-31)平台:x86_64-w64-mingw32/x64(64位)在以下环境下运行:Windows> = 8 x64(内部版本9200)语言环境:[1] LC_COLLATE =瑞典_瑞典1252 LC_CTYPE =瑞典_瑞典1252 LC_MONETARY =瑞典_瑞典1252 LC_NUMERIC = C[5] LC_TIME =瑞典_瑞典.1252附带的基本软件包:[1]统计图形grDevices utils数据集方法库其他附件包:[1] zoo_1.8-0 dygraphs_1.1.1.4 plotly_4.7.0.9000 reshape2_1.4.2 ggplot2_2.2.1.9000 lubridate_1.6.0 readxl_1.0.0 

谢谢!

解决方案

我认为问题在于ggplot2与plotly之间的交互.直接使用plot_ly函数

  p<-plot_ly(df,x =〜value,y =〜Price,type ='bar',split =〜Type)%&%;%布局(yaxis = list(title ='Count'),barmode ='stack')p 

Im facing some issues with ggplot2 and plotly. When creating a bar chart with ggplot2 and pass it into the function ggplotly the bars are mid air when deselecting variables. The graph is not behaving as the examples here.

Example:

library(ggplot2)
library(reshape2)
library(plotly)

df1 <- data.frame("Price" = rnorm(3, mean = 100, sd = 4), 
                 "Type" = paste("Type", 1:3))

df2 <- data.frame("Price" = rnorm(3, mean = 500, sd = 4), 
                  "Type" = paste("Type", 1:3))

df <- rbind(df1, df2)

df$Dates <- rep(c("2017-01-01", "2017-06-30"), 3)

df <- melt(df, measure.vars = 3)

p <- ggplot(df, aes(fill=Type, y=Price, x=value)) + 
  geom_bar(stat="identity", position = "stack")

ggplotly(p)

Im running on following:

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252    LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C                   
[5] LC_TIME=Swedish_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] zoo_1.8-0          dygraphs_1.1.1.4   plotly_4.7.0.9000  reshape2_1.4.2     ggplot2_2.2.1.9000 lubridate_1.6.0    readxl_1.0.0

Thanks!

解决方案

I think the problem is in the interaction between ggplot2 and plotly.Use plot_ly function directly

p <- plot_ly(df, x = ~value, y = ~Price, type = 'bar',split=~Type) %>%
  layout(yaxis = list(title = 'Count'), barmode = 'stack')
p

这篇关于取消选择变量时,条形图会“显示" *“苍蝇"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:34