格子上的直方图

发布于 2024-12-29 22:54:01 字数 258 浏览 4 评论 0原文

由于基本 R 的 hist() 不报告百分比(并且 freq=FALSE)也没有帮助,因此我转向了 lattice

histogram(rnorm(10000))

请帮助我解决以下问题:

  1. 我怎样才能摆脱情节周围的框?
  2. 如何分别定义x/y标签和x/y轴的cex?
  3. 如何为 x 轴和 y 轴提供自定义名称?

Since hist() of the base R does not report percentages (and the freq=FALSE) does not help either, I turned to lattice.

histogram(rnorm(10000))

Please help me with the following:

  1. How can I get rid of the box arround the plot?
  2. How can I seperately define the cex of the x/y labels and x/y axis?
  3. How can I provide custom names to x and y axis?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心意如水 2025-01-05 22:54:01

或者,如果您想坚持使用 hist(),您可以稍微修改它,如下所示。

该函数调用一次 hist() 来获取其返回值,该返回值是一个包含有关直方图结构的各种有用信息的对象。然后,它使用 (a) 箱的宽度和 (b) 每个条形的密度来计算 (c) 每个条形中观测值的百分比。

histPercent <- function(x, ...) {
   H <- hist(x, plot = FALSE)
   H$density <- with(H, 100 * density* diff(breaks)[1])
   plot(H, freq = FALSE, ...)
}

histPercent(rnorm(10000), col="dodgerblue", las=1,
            xlab="Echs-axis", ylab="Why-axis")

在此处输入图像描述

Or, if you want to stick with hist(), you can modify it slightly, as shown below.

This function calls hist() once to get its return value, which is an object containing all sorts of useful information about the structure of the histogram. It then uses (a) the width of the bins and (b) the density for each bar to calculate (c) the percentage of the observations falling in each bar.

histPercent <- function(x, ...) {
   H <- hist(x, plot = FALSE)
   H$density <- with(H, 100 * density* diff(breaks)[1])
   plot(H, freq = FALSE, ...)
}

histPercent(rnorm(10000), col="dodgerblue", las=1,
            xlab="Echs-axis", ylab="Why-axis")

enter image description here

水晶透心 2025-01-05 22:54:01

这应该可以帮助您开始:

library(lattice)
histogram(rnorm(10000),     
    main=list(
        label="Main plot title",
        cex=1.5),
    xlab=list(
        label="Custom x-axis label",
        cex=0.75),
    ylab=list(
        label="My very own y-axis label",
        cex=1.2),
    scales=list(cex=0.5),
    par.settings = list(axis.line = list(col = 0))
)

在此处输入图像描述

This should get you started:

library(lattice)
histogram(rnorm(10000),     
    main=list(
        label="Main plot title",
        cex=1.5),
    xlab=list(
        label="Custom x-axis label",
        cex=0.75),
    ylab=list(
        label="My very own y-axis label",
        cex=1.2),
    scales=list(cex=0.5),
    par.settings = list(axis.line = list(col = 0))
)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文