R:一组图表

发布于 2025-02-12 18:48:32 字数 1026 浏览 1 评论 0原文

我想创建一个类似地块的集合:

到目前为止,我已经设法创建了一个这样的图:

ggplot (df, aes (x, y)) + geom_point (col = 'yellow') + xlab ("A") + ylab ("B") + ggtitle ("Dose0.1") + geom_abline (slope = 1, linetype = 2, color = "red")

在轴上校准的措施

最好是在轴上进行功能

示例数据的形式:

structure(list(Np. = 1:32, A = c(62L, 62L, 54L, 54L, 10L, 10L, 
14L, 14L, 50L, 50L, 43L, 43L, 22L, 22L, 48L, 48L, 34L, 34L, 57L, 
57L, 60L, 60L, 1L, 1L, 63L, 63L, 2L, 2L, 44L, 44L, 34L, 57L), 
    B = c(1L, 7L, 2L, 29L, 1L, 15L, 27L, 28L, 14L, 15L, 48L, 
    49L, 1L, 2L, 1L, 21L, 18L, 19L, 23L, 24L, 14L, 15L, 29L, 
    31L, 1L, 2L, 1L, 36L, 2L, 19L, 19L, 23L), Dose = c(0.1, 1, 
    10, 1, 1, 0.1, 1, 1, 1, 1, 1, 1, 1, 0.1, 0.1, 0.1, 0.1, 0.1, 
    0.1, 0.1, 0.1, 0.1, 0.1, 10, 10, 10, 10, 10, 10, 10, 1, 1
    )), class = "data.frame", row.names = c(NA, -32L))

I would like to create a collection of plots like this:
enter image description here

So far I have managed to create a single such plot:

ggplot (df, aes (x, y)) + geom_point (col = 'yellow') + xlab ("A") + ylab ("B") + ggtitle ("Dose0.1") + geom_abline (slope = 1, linetype = 2, color = "red")

With calibrated measures on the axes

Preferably in the form of a function

Example data:

structure(list(Np. = 1:32, A = c(62L, 62L, 54L, 54L, 10L, 10L, 
14L, 14L, 50L, 50L, 43L, 43L, 22L, 22L, 48L, 48L, 34L, 34L, 57L, 
57L, 60L, 60L, 1L, 1L, 63L, 63L, 2L, 2L, 44L, 44L, 34L, 57L), 
    B = c(1L, 7L, 2L, 29L, 1L, 15L, 27L, 28L, 14L, 15L, 48L, 
    49L, 1L, 2L, 1L, 21L, 18L, 19L, 23L, 24L, 14L, 15L, 29L, 
    31L, 1L, 2L, 1L, 36L, 2L, 19L, 19L, 23L), Dose = c(0.1, 1, 
    10, 1, 1, 0.1, 1, 1, 1, 1, 1, 1, 1, 0.1, 0.1, 0.1, 0.1, 0.1, 
    0.1, 0.1, 0.1, 0.1, 0.1, 10, 10, 10, 10, 10, 10, 10, 1, 1
    )), class = "data.frame", row.names = c(NA, -32L))

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

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

发布评论

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

评论(2

友欢 2025-02-19 18:48:32

如果要在自己的函数中写入它,可以从rlang中组合{{}},告诉R,它应该寻找您的x 和y在这样的数据中参数:

df <- structure(list(Np. = 1:32, A = c(62L, 62L, 54L, 54L, 10L, 10L, 
                                       14L, 14L, 50L, 50L, 43L, 43L, 22L, 22L, 48L, 48L, 34L, 34L, 57L, 
                                       57L, 60L, 60L, 1L, 1L, 63L, 63L, 2L, 2L, 44L, 44L, 34L, 57L), 
                     B = c(1L, 7L, 2L, 29L, 1L, 15L, 27L, 28L, 14L, 15L, 48L, 
                           49L, 1L, 2L, 1L, 21L, 18L, 19L, 23L, 24L, 14L, 15L, 29L, 
                           31L, 1L, 2L, 1L, 36L, 2L, 19L, 19L, 23L), Dose = c(0.1, 1, 
                                                                              10, 1, 1, 0.1, 1, 1, 1, 1, 1, 1, 1, 0.1, 0.1, 0.1, 0.1, 0.1, 
                                                                              0.1, 0.1, 0.1, 0.1, 0.1, 10, 10, 10, 10, 10, 10, 10, 1, 1
                           )), class = "data.frame", row.names = c(NA, -32L))

library(ggplot2)
plot <- function(dataframe, xvalue, yvalue, grid){
ggplot(dataframe, aes({{xvalue}}, {{yvalue}})) + 
  geom_point(col = 'yellow') + 
  xlab ("A") + ylab ("B") + 
  geom_abline(slope = 1, linetype = 2, color = "red") +
  theme_bw() +
  facet_grid(~Dose)
}

plot(df, A, B, "Dose")

“”

If you want to write it in your own function, you can combine the {{}} from rlang to tell R that it should look for your x and y arguments inside the data like this:

df <- structure(list(Np. = 1:32, A = c(62L, 62L, 54L, 54L, 10L, 10L, 
                                       14L, 14L, 50L, 50L, 43L, 43L, 22L, 22L, 48L, 48L, 34L, 34L, 57L, 
                                       57L, 60L, 60L, 1L, 1L, 63L, 63L, 2L, 2L, 44L, 44L, 34L, 57L), 
                     B = c(1L, 7L, 2L, 29L, 1L, 15L, 27L, 28L, 14L, 15L, 48L, 
                           49L, 1L, 2L, 1L, 21L, 18L, 19L, 23L, 24L, 14L, 15L, 29L, 
                           31L, 1L, 2L, 1L, 36L, 2L, 19L, 19L, 23L), Dose = c(0.1, 1, 
                                                                              10, 1, 1, 0.1, 1, 1, 1, 1, 1, 1, 1, 0.1, 0.1, 0.1, 0.1, 0.1, 
                                                                              0.1, 0.1, 0.1, 0.1, 0.1, 10, 10, 10, 10, 10, 10, 10, 1, 1
                           )), class = "data.frame", row.names = c(NA, -32L))

library(ggplot2)
plot <- function(dataframe, xvalue, yvalue, grid){
ggplot(dataframe, aes({{xvalue}}, {{yvalue}})) + 
  geom_point(col = 'yellow') + 
  xlab ("A") + ylab ("B") + 
  geom_abline(slope = 1, linetype = 2, color = "red") +
  theme_bw() +
  facet_grid(~Dose)
}

plot(df, A, B, "Dose")

Created on 2022-07-04 by the reprex package (v2.0.1)

陈年往事 2025-02-19 18:48:32

您可能需要更改格式化,但本质上是:

df$dose  <- factor(df$Dose)
ggplot (df, aes (A, B)) + 
    geom_point(aes(color = dose, shape = dose)) + 
    xlab ("A") + 
    ylab ("B") + 
    geom_abline(slope = 1, linetype = 2, color = "black") +
    facet_wrap(vars(dose)) + 
    theme_bw()

”在此处输入图像说明”

You may want to change formatting a little but essentially:

df$dose  <- factor(df$Dose)
ggplot (df, aes (A, B)) + 
    geom_point(aes(color = dose, shape = dose)) + 
    xlab ("A") + 
    ylab ("B") + 
    geom_abline(slope = 1, linetype = 2, color = "black") +
    facet_wrap(vars(dose)) + 
    theme_bw()

enter image description here

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