格式化和处理来自R包"hexbin"的图. [英] Formatting and manipulating a plot from the R package "hexbin"

查看:416
本文介绍了格式化和处理来自R包"hexbin"的图.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用包hexbin生成图:

# install.packages("hexbin", dependencies=T)
library(hexbin)


set.seed(1234)
x <- rnorm(1e6)
y <- rnorm(1e6)
hbin <- hexbin(
  x   = x
  , y = y
  , xbin = 50
  , xlab = expression(alpha)
  , ylab = expression(beta)
)


## Using plot method for hexbin objects:
plot(hbin, style = "nested.lattice")

abline(h=0)

这似乎生成了一个S4对象(hbin),然后我使用plot对其进行了绘制. 现在,我想使用abline在该绘图上添加一条水平线,但不幸的是,这会产生错误:

This seems to generate an S4 object (hbin), which I then plot using plot. Now I'd like to add a horizontal line to that plot using abline, but unfortunately this gives the error:

plot.new尚未被调用

plot.new has not yet been called

我也不知道如何操作例如轴标签的位置(字母和beta在数字内),更改图例的位置等.

I have also no idea, how I can manipulate e.g. the position of the axis labels (alpha and beta are within the numbers), change the position of the legend, etc.

我对OOP很熟悉,但到目前为止,我仍无法了解plot()如何处理对象(它调用对象的某些方法吗?)以及如何操作生成的图.

I'm familiar with OOP, but so far I could not find out how plot() handles the object (does it call certain methods of the object?) and how I can manipulate the resulting plot.

为什么我不能简单地在地块上画一条线?

如何操作轴标签?

推荐答案

使用十六进制bin的晶格版本-hexbinplot().使用panel您可以添加线,使用style您可以选择其他可视化六边形的方式.有关更多信息,请参见hexbinplot的帮助.

Use lattice version of hex bin - hexbinplot(). With panel you can add your line, and with style you can choose different ways of visualizing hexagons. Check help for hexbinplot for more.

library(hexbin)
library(lattice)
x <- rnorm(1e6)
y <- rnorm(1e6)
hexbinplot(x ~ y, aspect = 1, bins=50, 
           xlab = expression(alpha), ylab = expression(beta), 
           style = "nested.centroids",
           panel = function(...) {
             panel.hexbinplot(...)
             panel.abline(h=0)
             })

这篇关于格式化和处理来自R包"hexbin"的图.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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