同轴线散点图 [英] scatterplot with equal axes

查看:168
本文介绍了同轴线散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  DataFrame<  -  data.frame(x = runif(25 ),y = runif(25),
z = sample(letters [1:4],25,rep = TRUE))

并使用莱迪思包,我可以用等轴线(以1:1线穿过中心)绘制散点图,其中包含以下几行:

  xyplot(y〜x | z,data = DataFrame,
scales = list(relation =free),
prepanel = function (x,y,...){
rg < - 范围(na.omit(c(x,y)))
list(xlim = rg,ylim = rg)
} ,panel = function(x,y,...){
panel.abline(0,1)
panel.xyplot(x,y,...)
})

在ggplot2中,我得到了很多:

  ggplot(data = DataFrame)+ geom_point(aes(x = x,y = y))+ 
facet_grid(〜z,scales =free)+ coord_equal = 1)+
geom_abline(截距= 0,slope = 1)

但我不确定coord_equal()是我正在寻找的函数。什么可能是ggplot2中的等效函数调用?

解决方案

你的问题在于设置自由分面比例。一旦你将facet scale设置为free,你就不能添加 coord_equal()如果你消除了空闲的比例,那么 coord_equal()正常工作。


I have a data set like this one below:

DataFrame <- data.frame(x=runif(25),y=runif(25),
                        z=sample(letters[1:4],25,rep=TRUE))

and using the Lattice package, I can make a scatter plot with equal axes (with a 1:1 line going through the centre) with the following lines:

xyplot(y ~ x | z, data=DataFrame,
       scales=list(relation="free"),
       prepanel=function(x,y,...) {
         rg <- range(na.omit(c(x,y)))
         list(xlim=rg,ylim=rg)
       },panel=function(x,y,...) {
         panel.abline(0,1)
         panel.xyplot(x,y,...)
       })

In ggplot2, I have gotten this far:

ggplot(data=DataFrame) + geom_point(aes(x=x,y=y)) +
  facet_grid(~z,scales="free") + coord_equal(ratio=1) +
  geom_abline(intercept=0,slope=1)

But I'm not sure that coord_equal() is the function I'm looking for. What might be the equivalent function call in ggplot2?

解决方案

Your problem lies in setting free facet scales. Once you set the facet scales to be free, you can't then add coord_equal() If you eliminate the free scales, then coord_equal() works properly.

这篇关于同轴线散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆