本文介绍了在另一个绘图的绘图区域内添加小直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

是否有方法在另一个绘图的绘图区域内添加直方图,但与基本绘图坐标系统无关?在我的情况下,我想添加一个直方图作为一个等值线图的图例(直方图将显示每个类中的区域数量),但是这个问题可以很容易地应用于任何绘图。例如

  plot(1:10)
rect(1,7,4,9,col =grey )


我可以在灰色矩形位于上面的图表中出现直方图吗?目前,如果我尝试创建1:10系列的直方图,它会使用散点图设置的坐标系统,并且我无法弄清楚如何(或者是否有可能)重新定位并调整其大小以显示(1:10)
hist(1:10,col =gray90)。

  ,add = TRUE)

subplot

在TutorialDemos软件包中(也可以在Hmisc软件包中复制)。 子图可以使用用户坐标,但可以使用 grconvertX / grconvertY 从标准化的地块坐标转换而来。

  library(TeachingDemos)
plot(1:10)
subplot (hist(1:10),grconvertX(c(.1,.4),npc),grconvertY(c(.7,.9),npc))

>

给出:


Is there a way to add a histogram inside the plot area of another plot, but independent of the "base" plot's coordinate system? In my case, I want to add a histogram as a legend to a choropleth map (the histogram would show the number of regions that fall in each class), but the question could just as easily apply to any plot. For example

plot(1:10)
rect(1, 7, 4, 9, col="gray")

Could I make a histogram appear where the gray rectangle is in the above plot? Currently, if I try to create a histogram of the series 1:10, it appears using the coordinate system set by the scatterplot, and I can't figure out how (or whether it is possible) to reposition it and resize it to appear in the top left.

plot(1:10)
hist(1:10, col="gray90", add=TRUE)
解决方案

Try subplot in the TeachingDemos package (and also replicated in the Hmisc package). subplot takes user coordinates but grconvertX / grconvertY can be used to convert from normalized plot coordinates. See comments below for additional discussion.

library(TeachingDemos)
plot(1:10)
subplot(hist(1:10), grconvertX(c(.1, .4), "npc"), grconvertY(c(.7, .9), "npc"))

which gives:

这篇关于在另一个绘图的绘图区域内添加小直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:14