Сохранение графика корреляционной матрицы в формате PDF

У меня есть объект корреляционной матрицы, который я создал с помощью corrplot

p1 <- corrplot(correlations_history, method = "number", type = "lower", title = "Regional Factor Correlation Matrix over history", mar = c(0,0,1,0), number.cex = 0.5, number.digits = 2)

Пытаюсь сохранить в pdf. Я почему-то не могу понять, как это сделать. Любая помощь приветствуется. Благодарю вас!


person bigjdawg43    schedule 31.05.2018    source источник


Ответы (2)


Запустите графический драйвер PDF, затем вызовите свой график.

pdf(file = "yourfilename.pdf")

corrplot(correlations_history, method = "number", type = "lower", 
title = "Regional Factor Correlation Matrix over history", 
mar = c(0,0,1,0), number.cex = 0.5, number.digits = 2)

dev.off()
person Joe    schedule 03.06.2018

Хотя это старый вопрос, я подумал о предоставлении альтернативного подхода с использованием recordPlot(), replayPlot() и ggsave().

p1 <- { # Prepare the Corrplot 
       corrplot(correlations_history, 
                method = "number", 
                type = "lower", 
                title = "Regional Factor Correlation Matrix over history", 
                mar = c(0,0,1,0), 
                number.cex = 0.5, 
                number.digits = 2);
        # Call the recordPlot() function to record the plot
        recordPlot()
       }

# In case if you want to save the image using ggsave
# replayPlot basically prints the plot.
library(ggplot2)
ggsave(filename = "p1.pdf", plot = replayPlot(p1))
person Rahi    schedule 29.07.2021