I am exporting editable ggplots to powerpoint slides. Each graph has a correlation. When the correlation R value is negative, this exports as a box in the graph, instead of a negative sign in text.
An example of the resulting issue is shown as an image and an example of my code is below. Thanks for any insight!
Below is the code I've been using to generate the graphs:
# generate plot
p< - data %>%
ggplot(aes_string(x = "x_value", y = "y_value")) +
geom_smooth(method = "lm", formula = y ~x, se=TRUE, color="black") +
geom_point(aes(shape=group, fill= group), size=4) +
labs(title = paste("Title"),
y = "Y title",
x= "X title" ) +
scale_x_continuous(breaks=seq(0, 10, 1), limits=c(0, 10)) +
scale_y_continuous(breaks=seq(0, 400, 25), limits=c(0, 400))+
theme_bw() +
theme(plot.title = element_text(face = "bold", size = 20),
legend.position = "none",
axis.title = element_text(face="bold", size=24),
axis.text = element_text(size=24)
) +
stat_cor(label.y.npc="top", label.x.npc = "left",
size=7,
method="pearson")
# creating a new slide and inserting the plot
graphs <- add_slide(graphs, layout = "Title and Content", master = "Office Theme")
graphs <- ph_with(graphs, dml(ggobj = p), location = ph_location_fullsize())
I was able to resolve this by specifying output.type="text" to the stat_cor command. This successfully exported the negative sign as a text box, instead of an object that did not display in powerpoint. Code below:
stat_cor(label.y.npc="top", label.x.npc = "left",
size=7,
method="pearson", output.type = "text")