1

I'm working with Python and R Markdown with reticulate.

It really works great but I have one problem:

A plot made with Python (seaborn) is not fully shown in my PDF and I don't know why.

This is how it looks on the PDF:

Python in R Markdown

(Yes, I know, the heatmap doesn't make sense, it's only for demonstration purposes). As you can see there would be enough space for the row names and column names but you don't see them completely. Changing fig.width and fig.height does not really lead to better results. Do you have an idea what I can do that it is garanteed that the whole graphic is shown?

Here is my full code:

---
output: 
  pdf_document:
    number_sections: true
lang: de
fontsize: 12pt
header-includes: 
  - \usepackage{float}
  - \pagenumbering{gobble}
---
knitr::opts_chunk$set(
  fig.height = 2,
  fig.width = 5,
  echo = TRUE,
  fig.align  = "center",
  fig.pos = "H",
  out.extra = "", 
  warning = FALSE,
  message = FALSE)
library(reticulate)

import seaborn as sns
import pandas as pd
data = pd.read_csv("gapminder_full.csv")
ct = pd.crosstab(index = data["continent"], 
                 columns = data["year"],
                 normalize = "index")
sns.heatmap(ct)

I'm not really sure if Python or seaborn is the problem. My impression is that only ggplot really works fine in R Markdown ... Probably you have a more general idea?

TobiSonne
  • 1,044
  • 7
  • 22
  • Sometimes changing the output to HTML can render a better output, and then you can PRINT the PDF from the web browser, depending on your flexibility of file formatting. – Daniel_j_iii May 07 '21 at 20:17

1 Answers1

0

I have a hint:

The plot is saved in the folder ..._files/figure-latex and in a separate pdf file and already in this file the plot is not complete. So I've set plt.subplots(figsize=(10,6)) and everything is better but not perfect ...

TobiSonne
  • 1,044
  • 7
  • 22