我尝试使用 ggplotly 函数将 ggplot geom-tile 图表转换为 plotly 。然而,我意识到结果是不同的。请参阅下面的链接以查看差异。除此之外,ggplotly 图表也缺少颜色条。请帮忙。
这是我提到的代码:https ://www.r-graph-gallery.com/285-waffer-map.html
代码:
madeUp=read.table("https://raw.githubusercontent.com/holtzy/R-graph-gallery/master/DATA/madeUp.csv", sep=",", header=T)
library(tidyverse)
theData <- madeUp %>%
group_by(X.Axis, Y.Axis, Group) %>%
dplyr::summarize(statistic=mean(randVals, na.rm = TRUE))
fig <- ggplot(theData, aes(X.Axis, Y.Axis)) +
coord_cartesian(xlim = c(0,20), ylim = c(0,20)) +
scale_x_continuous(breaks = seq(0,20)) +
scale_y_continuous(breaks = seq(0,20))+
geom_tile(aes(fill=statistic))+
guides(fill=guide_legend(title='Legend'))+
theme(
panel.background = element_rect(fill= 'white', color = 'white'),
panel.grid.major = element_line(color='#E0E0E0'),
panel.grid.minor = element_line(color='#E0E0E0')
)+
ggtitle('Wafer Map')+
facet_wrap(~Group)+
scale_fill_gradientn(colors = rainbow(100))
#Convert to ggplotly chart
fig <- ggplotly(fig)
谢谢