我无法将ggplot
包含在ggplotly()
中的以下shape
的图例展示为只有一种美学。它目前为每个图例条目显示三个变量(color
,linetype
,aes()
),但我只想显示一个。
此图中只有一个linetype
值发生了变化(aes()
),但其他值对应于特定变量,并且应该在我网站上的许多图表中保持一致。在我的情况下,简单地从绘图中删除其他tooltip
值并不是一个可行的解决方案,因为我希望它们在其他类似的图中进行更改。此外,隐藏图例并修改library(ggplot2)
library(plotly)
#aes lists
solute_colors <- c("NO3" = "#BF1616")
source_shapes <- c("rain"= 21)
location_linetypes <- c("1"= 2,"2"= 1,"3"= 3)
#create dataframe
data <- data.frame(
date = c(1966, 1970, 1972, 1979, 1989, 1990, 1998, 2000),
concentration = sample(1:8),
solute = c("NO3", "NO3", "NO3", "NO3", "NO3", "NO3", "NO3", "NO3"),
location = c("3", "1", "2", "3", "2", "1", "1", "2"),
source = c("rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain")
)
#ggplot
ggplot(data, aes(x= date, y= concentration, linetype= location, color= solute, shape= source))+
geom_point() +
geom_line() +
scale_shape_manual(values = source_shapes) +
scale_color_manual(values = solute_colors)+
guides(shape = F, color = F)+ #removes shape and source legends in ggplot, but not in ggplotly
scale_linetype_manual(values = location_linetypes)
以显示信息,但不是最终结果。
运行时,以下代码:
linetype
图例仅显示ggplotly
,这是期望的结果(见here)。但是,将其包装在#ggplot p
p<-ggplot(data, aes(x= date, y= concentration, linetype= location, color= solute, shape= source))+
geom_point() +
geom_line() +
scale_shape_manual(values = source_shapes) +
scale_color_manual(values = solute_colors)+
guides(shape = F, color = F)+ #removes shape and source legends in ggplot, but not in ggplotly
scale_linetype_manual(values = location_linetypes)
#wrap p in ggplotly
ggplotly(p)
aes()
图例显示的是图例中相同行中的三个ggplotly
值
。
如果在ggplot
中换行或在图例中为其手动编码,如何覆盖此更改?我在ggplot中添加了主题,可以更改ggplotly
和legend.position
中的图例(例如legend.title
和2013-01-01 04:23:56-05:00
)但我还没有找到任何可以控制实际的内容变量显示。
我在Windows 10上使用R版本3.4.0(RStudio版本1.0.143)。非常感谢任何帮助!