Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 使用ggplotly时保持纵横比_R_Ggplot2_Plotly - Fatal编程技术网

R 使用ggplotly时保持纵横比

R 使用ggplotly时保持纵横比,r,ggplot2,plotly,R,Ggplot2,Plotly,我有一个ggplot hexbin图表,我想用ggplotly显示。但是,当我使用ggplotly函数时,先前为gplot图表固定的纵横比丢失 最简单的工作示例: library(ggplot2) library(plotly) library(RColorBrewer) set.seed(11) df<-data.frame(xvar=rnorm(1000,0,4),yvar=rnorm(1000)) #nicer colours palette <- colorRampPal

我有一个ggplot hexbin图表,我想用ggplotly显示。但是,当我使用ggplotly函数时,先前为gplot图表固定的纵横比丢失

最简单的工作示例:

library(ggplot2)
library(plotly)
library(RColorBrewer)

set.seed(11)
df<-data.frame(xvar=rnorm(1000,0,4),yvar=rnorm(1000))

#nicer colours
palette <- colorRampPalette(rev(brewer.pal(11,'Spectral')))
colours<-palette(32)

p1<-ggplot(df,aes(x=xvar,y=yvar))+ coord_fixed(ratio=1)+
  stat_binhex(bins=50)+scale_fill_gradientn(colours=colours)
p1
ggplotly(p1)
库(ggplot2)
图书馆(绘本)
图书馆(RColorBrewer)
种子(11)

df不幸的是,
ggplot2
中仍有许多内容在传输到
plotly
后无法保存,请参阅以获取概述。有关此问题,请参阅。我知道此功能不可用。我的方法非常接近于保持纵横比,但我相信由于传说的原因,会有一个小偏差。我的问题的目的是想知道是否有办法。
ratioaxes<-(max(df$yvar)-min(df$yvar))/(max(df$xvar)-min(df$xvar))
ggplotly(p1,height=ratioaxes*500,width=500)