Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用ggplot2中的plotly时缺少图例和颜色_R_Ggplot2_Legend_Boxplot_Plotly - Fatal编程技术网

R 使用ggplot2中的plotly时缺少图例和颜色

R 使用ggplot2中的plotly时缺少图例和颜色,r,ggplot2,legend,boxplot,plotly,R,Ggplot2,Legend,Boxplot,Plotly,我用ggplot2制作了一个箱线图,它在R中呈现出美丽的颜色,并带有相应的图例。当我将其导出到plotly时,方框图都是红色的,并且图例已消失。 我不能在这里发布情节图片,因为它不允许我,但我的代码如下: r <- ggplot(data=all.data, aes(factor(Year), Data))+xlab("Year") r <- r + geom_boxplot(outlier.shape = NA, aes(fill = factor(Month))) r <

我用
ggplot2
制作了一个箱线图,它在R中呈现出美丽的颜色,并带有相应的图例。当我将其导出到plotly时,方框图都是红色的,并且图例已消失。 我不能在这里发布情节图片,因为它不允许我,但我的代码如下:

r <- ggplot(data=all.data, aes(factor(Year), Data))+xlab("Year")
r <- r + geom_boxplot(outlier.shape = NA, aes(fill = factor(Month))) 
r <- r + scale_y_continuous(limits = c(-1, 6.5))
r <- r+ scale_fill_discrete(name = "Month")
r
gg <- ggplotly(r,kwargs=list(world_readable=FALSE))

r您是否安装了最新的
ggplot2
plotly
软件包?我尝试了一个简单的条形图,但无法重现您的问题

我已安装以下版本:

packageVersion("ggplot2")
# [1] ‘1.0.1’
packageVersion("plotly")
# [1] ‘1.0.7’
packageVersion("shiny")
# [1] ‘0.12.2’

如果您的版本更大,则可以考虑升级到最新的最大值。

在我的机器上,这个愚蠢的示例(类似于您不完整的代码片段):

library(plotly)
图书馆(GG2)
所有数据
library(plotly)
library(ggplot2)

all.data <- data.frame(Year = c(2000, 2000, 2005, 2005),
                       Month = c("Jan", "Jan", "Jul", "Jul"),
                       Data = c(0, 3.2, 3, 4))

r <- ggplot(data = all.data, aes(factor(Year), Data)) + xlab("Year")
r <- r + geom_boxplot(outlier.shape = NA, aes(fill = factor(Month))) 
r <- r + scale_y_continuous(limits = c(-1, 6.5))
r <- r + scale_fill_discrete(name = "Month")
r

Sys.setenv("plotly_username" = "MyCoooolUsername")
Sys.setenv("plotly_api_key" = "MySeCrEtPWD")
plotly:::verify("username")
plotly:::verify("api_key")
gg <- ggplotly(r,world_readable=TRUE)
gg