【问题标题】:Convert built-in plots in high-quality graphics for publications?为出版物转换高质量图形的内置图?
【发布时间】:2021-01-01 19:52:37
【问题描述】:

我使用 PUPAIM 包生成吸附等温线,例如redlichpanalysis(Ce,Qe)

例如使用以下变量:

install.packages("PUPAIM")
library(PUPAIM)
library(nls2)
Ce <- c(1.447071, 1.605402, 2.196297)
Co <- c(2,3,4)
Qe <- (Co-Ce)*100/0.33
redlichpanalysis(Ce,Qe)
#give immediately the statistics and basic plot as output format  

这会生成一个情节:

如何自定义绘图程序并获得类似于ggplot2的高质量图形? (我的其余图形是在 ggplot 2 中制作的。这就是我强调这个问题的原因)。

我搜索了类似的问题,发现例如ggplotify 包。坦白说,我真的不明白。如果我更改 ggplot 对象中的绘图对象,那么我该如何自定义它。例如,我尝试添加“theme_bw()”,但失败了。

我需要重新调整坐标轴,添加类似于 theme_bw() 的布局,添加具有适当单位的坐标轴标签,并且可能还需要调整测量点的样式以及回归本身。

非常感谢关于如何自定义给定的基本内置图的任何建议...

【问题讨论】:

  • @BenBolker:我编辑帖子

标签: r ggplot2


【解决方案1】:

如果我们查看PUPAIM::redlichpanalysissource code,我们会发现绘图很简单:

redlichpanalysis <- function(Ce, Qe){
    x <- Ce
    y <- Qe
    data <- data.frame(x, y)
    n<- nrow(na.omit(data))
    print("NLS2 Analysis for Redlich Peterson Isotherm Model")
    fit257 <- (Qe ~ (Arp*Ce)/(1+(Krp*(Ce^b))))
    start <- data.frame(Arp = c(1, 100), Krp = c(1, 100), b = c(0, 1))
    set.seed(511)
    fit258 <- nls2(fit257, start = start, control = nls.control(maxiter = 50, warnOnly = TRUE), algorithm = "port")
#<removed irrelevant lines here>
    plot(x, y, main = "Redlich Peterson Isotherm", xlab = "Ce", ylab = "Qe")
    lines(x, predict(fit258), col = "black")
#<more irrelevant lines here>
}

我们可以用ggplot做同样的事情:

library(ggplot2)
library(PUPAIM)

startfit <- (Qe ~ (Arp*Ce)/(1+(Krp*(Ce^b))))
start <- data.frame(Arp = c(1, 100), Krp = c(1, 100), b = c(0, 1))
set.seed(511)
endfit <- nls2(startfit, start = start, control = nls.control(maxiter = 50, warnOnly = TRUE), algorithm = "port")
predict(endfit)

data.frame(Ce,Qe,Predict = predict(endfit)) %>% 
ggplot(aes(x=Ce, y = Qe)) +
  geom_point() +
  geom_line(aes(y = Predict)) +
  ggtitle("Redlich Peterson Isotherm") +
  theme_bw()

【讨论】:

  • 但这并没有显示预测值,这可能是要点(根据实现方式,很难从函数结果中提取这些值。我的建议实际上是将整个代码复制到您自己的函数中,返回预测值,然后从那里开始...
  • 谢谢伊恩!我认为,这是使用您建议的源代码的最佳方式。
  • 你可以向维护者建议,如果包稍微模块化一点,它会有多大用处......
猜你喜欢
  • 1970-01-01
  • 2018-06-30
  • 2013-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多