scale_y_reverse() 在 ggplot2 中不起作用

sov*_*von 2 r ggplot2

我正在尝试反转 y 轴并将 x 轴放在顶部。一切正常,但是当我尝试在scale_y_reverse()函数中提供一系列 y 轴时,y 轴消失并显示警告消息 -Removed 44 rows containing missing values (geom_point)这是我的代码 -

ggplot(out,aes(x=self_w,y=self_h,col=log(out$force),xlim(0,593),ylim(0,790)))+  geom_point(size=log(out$force))+
  scale_fill_continuous(low="green",high="red") +scale_x_continuous(limits=c(0,593),expand=c(0,0),position = "top")+
  scale_y_reverse(limits=c(0,790),expand=c(0,0)) 
Run Code Online (Sandbox Code Playgroud)

是我的数据集。如果你删除scale_y_reverse()它的参数会正常工作,但这不是我需要的。色标也没有从green到 变化red。有人可以帮我找到问题吗?谢谢。

eip*_*i10 6

当您反转轴时,您还需要反转限制。所以改为scale_y_reverse(limits=c(790,0), expand=c(0,0)).

其他一些事情:

  1. 将 的所有实例更改out$forceforce,因为您不应在aes.

  2. geom_pointsize=log(force)应该被包裹在aes()

  3. 看着你的数据,force往往是零,所以log(force)-Inf在这些情况下。