除了 texplot 之外,如何在 R 中将文本转换为图像?

How to convert text to image in R other than texplot?

我在 R 中进行了线性回归,并提取了显着变量及其 p 值。我需要导入那些要在 Power BI 中导入的变量。但是,Power BI 仅支持来自 R 的视觉效果,回归结果为文本形式。有什么方法可以将它转换成图像,就像通常在 R 中弹出的图一样?谢谢

编辑:Power BI 不支持 gplots 包。可以在此处找到支持的软件包 https://powerbi.microsoft.com/en-us/documentation/powerbi-service-r-visuals/#supported-packages

这是您问题的答案以及可重现的示例。您可以使用 gplots 包的 textplot 函数。

library(gplots) # For the textplot function
library(tidyverse) # Should be a part of all data science workflows
library(broom) # Gives us the tidy function

# Generate some dummy data for the regression
dummy_data <- data.frame(x = rnorm(327), y = rnorm(327))

# Run the regression and extract significant variables
reg <- lm(y ~ x, data = dummy_data) %>%
  tidy() %>%
  filter(term != "(Intercept)") %>%
  filter(p.value < 1.01) %>% # Change this to your desired p value cutoff
  select(term)

# Plot the significant variables as an image
textplot(reg$term)

如果你想让 R 与 PowerBI 对话,还有更好的选择。微软一直在越来越多的产品中构建对 R 的支持,PowerBI 现在拥有强大的 R 集成。检查一下:https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-r-scripts/