在R中显示水平图上的数据值 [英] Showing data values on levelplot in R

查看:154
本文介绍了在R中显示水平图上的数据值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在 R 中的levelplot(格子包)上显示数据值。如果有人帮我做到这一点,我将不胜感激。

解决方案

您可以编写自己的面板函数,例如:

  library(lattice)
x < - seq(pi / 4,5 * pi,length.out = 10)
y < - seq (外部(x ^ 2,y ^ 2,+)))
grid<< ; - expand.grid(x = x,y = y)
grid $ z <-cos(r ^ 2)* exp(-r /(pi ^ 3))

p < - levelplot(z〜x * y,grid,
panel = function(...){
arg< - list(...)
panel.levelplot(.. )
panel.text(arg $ x,arg $ y,round(arg $ z,1))})
print(p)
pre>


I wonder if it is possible to show data values on levelplot (lattice package) in R. I'd appreciate if someone help me to do that. Thanks in advance.

解决方案

You can write your own panel function, e.g.:

library("lattice")
x <- seq(pi/4, 5*pi, length.out=10)
y <- seq(pi/4, 5*pi, length.out=10)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2)*exp(-r/(pi^3))

p <- levelplot(z~x*y, grid, 
               panel=function(...) {
                       arg <- list(...)
                       panel.levelplot(...)
                       panel.text(arg$x, arg$y, round(arg$z,1))})
print(p)

这篇关于在R中显示水平图上的数据值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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