Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.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 缺少工具提示和冗余图例,使用几何图形栏绘制_R_Ggplot2_Plotly - Fatal编程技术网

R 缺少工具提示和冗余图例,使用几何图形栏绘制

R 缺少工具提示和冗余图例,使用几何图形栏绘制,r,ggplot2,plotly,R,Ggplot2,Plotly,我试图重现我找到的ggplotgeom\u bar示例。 代码相当简单 library(ggplot2) library(plotly) dat <- data.frame( time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")), total_bill = c(14.89, 17.23)) # No legend, since the information is redundant ggplot(data=dat

我试图重现我找到的ggplot
geom\u bar
示例。 代码相当简单

library(ggplot2)
library(plotly)

dat <- data.frame(
time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23))

# No legend, since the information is redundant
ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) +
geom_bar(colour="black", stat="identity") +
guides(fill=FALSE)

ggplotly()
我刚刚注意到,referenced by还提供了一种通过在ggplotly对象中手动禁用图例来消除图例的方法。例如:

library(ggplot2)
library(plotly)

dat <- data.frame( time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")), total_bill = c(14.89, 17.23))

# No legend, since the information is redundant
p <- ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) + geom_bar(colour="black", stat="identity") + guides(fill=FALSE)
p <- ggplotly(p)


for (i in 1:nrow(dat)){
    p$x$data[[i]]$text <- c(p$x$data[[i]]$text, "") 
    p$x$data[[i]]$showlegend <- FALSE
}
p
库(ggplot2)
图书馆(绘本)
dat解决方案发布于
bcdunbar

theme(legend.position = "none") +
ggplotly

p中转换为图例抑制,谢谢!这(使用p而不是p2)解决了工具提示的问题。知道这个传说吗?提交了一份错误报告。
theme(legend.position = "none") +