RMarkdown with beamer presentation generates ggplot graphs with wrong margins. What should I do? - pdf-generation

I'm using RMarkdown with beamer-presentation to generate slides in pdf format. All goes well when I am checking the code results in RStudio. However, when I knit the code, the plots generated get very bad margins and the title gets cut off as you can see in this image:
https://raw.githubusercontent.com/neylsoncrepalde/neylsoncrepalde.github.io/master/img/bad_graph.png
I have already tried reinstalling rmarkdown, reinstalling R, reinstalling RStudio with no success. I'm running on a 2012 Macbook with MacOS 10.13.6 (High Sierra). I installed R and RStudio with homebrew. This is the code I use.
---
title: "Test of bad margins graphs"
output:
beamer_presentation:
keep_tex: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(ggplot2)
data("diamonds")
```
##
```{r graph1}
ggplot(diamonds, aes(x = carat, y = price)) +
geom_point() +
labs(title = "Diamonds plot", subtitle = "A nice scatterplot with
ggplot2")
```
Any help would be great! Thanks in advance!

Related

Header loses uper case in rmarkdown + tufte

I'm trying to keep the uppercase part of the title in the page-headers; it shows ok in the title page, so I'm looking for a way to pass text as it is from the yaml header to the page headers, I've seen examples with plain latex where passing strings as they are is the default behavior, so I guess it is somewhere in the chain yaml-rmarkdown-tufte; my yaml header is the following, it renders "guatemala", so I'd like to have the capital G here.
link to log file
---
title: "Intercambio de experiencias en restauraciĆ³n de manglar: Guatemala"
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
tufte::tufte_html:
self_contained: yes
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
author: "Pronatura Veracruz"
date: "`r format(Sys.time(), '%d %B %Y')`"
link-citations: yes
bibliography: biblio.bib
lang: es
urlcolor: blue
linkcolor: blue
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}
\includegraphics[width=2in,height=2in]{lancha.jpg}\LARGE\\}
- \posttitle{\end{center}}
- \usepackage{tocloft}
---
TL;DR:
Install the soul latex package
Long version
The tufte class does not use the usual small caps from latex, but redefines them. To do this, it normally uses the soul package.
However the soul package is only an optional dependency of the tufte class. If it is installed, it will be used, if it is not installed, you can still compile the document, you just don't get all the features.
Now the unfortunate series of events continues. You are using tinytex, which by default is missing nearly all packages -- amongst the missing packages is the soul package. And because the soul package is only an optional dependency, tinytex's automatic installation of missing packages does not kick in.
To solve this, either manually install soul or (better) use a complete texlive installation instead of tinytex, so you'll never again have problems with missing packages.

How to use correct lang parameter?

I have a fresh Mediawiki installed into fresh UBUNTU 18 LTS... The ''SyntaxHighlight'' extension not works for Unix shell, lang="sh", lang="shell", lang="bash", ... no one is working. It is not at #Supported_languages, and there are no clues about how to install "Other markup".
At mediawiki.org/list there are no clues.
So, how to solve the problem? It is a config, env or syntax problem?
NOTES AND TESTS
Notes.
It is a corporative Wiki, no way to offer public URL... But it is a fresh, standard and controlled installation, all reproductive and standard.
The Wiki was configured with skin "Vector" and language "Brazilian Portuguese".
Tests.
Usage tests of mediawiki.org/Extension:SyntaxHighlight, the Python example.
1.1. With tag <syntaxhighlight>. Result: no highlight, same as <pre>.
1.2. With tag <source>. Result: no highlight, same as <pre>.
PHP example, fragment from wikipedia.org/PHP Syntax.
2.1. With tag <syntaxhighlight>. Result: no highlight, same as <pre>.
2.2. With tag <source>. Result: no highlight, same as <pre>.
The code fragments used in the tests:
def quickSort(arr):
less = []
pivotList = []
more = []
if len(arr) <= 1:
return arr
else:
pass
<title>PHP "Hello, World!" program</title>
<?php echo '<p>Hello World</p>'; ?>
MediaWiki Syntax highlighter used Pygments library, you should first download and install the extension:
Requirements
This version of the extension has been tested with Pygments 1.6, 2.0.2 and
MediaWiki 1.25 as of 2015-06-19. To get releases of this extension compatible
with earlier versions of MediaWiki, visit:
https://www.mediawiki.org/wiki/Special:ExtensionDistributor/SyntaxHighlight_GeSHi
Download
https://github.com/wikimedia/mediawiki-extensions-SyntaxHighlight_GeSHi/archive/master.tar.gz
Installation
Add this line to your LocalSettings.php:
wfLoadExtension( 'SyntaxHighlight_GeSHi' );
By default, this extension will use a bundled copy of Pygments 2.0.2. If you
would like to use a different copy of the library, you can set
$wgPygmentizePath to point to the path to the 'pygmentize' binary.
Usage
On the wiki page, you can now use "source" elements:
<source lang="php">
<?php
v = "string"; // sample initialization
?>
html text
<?php
echo v; // end of php code
?>
</source>
Parameters
For details information of these parameters, see the documentation of Pygments'
HtmlFormatter at http://pygments.org/docs/formatters/#HtmlFormatter.
lang; Defines the language.
line; Corresponds to linenos="inline" option.
start; Corresponds to linenostart opion.
enclose; If set to "none", corresponds to the nowrap=1 option.
inline; Corresponds to the nowrap=1 option.
highlight; Corresponds to hl_lines option (comma separated).
Note
Pygments is generous about creating HTML elements: highlighting large blocks of
code can easily generate enough of them to crash a browser. As a guard, syntax
highlighting is turned off for code fragments larger than 100 kB.

sphinx mathjax offline with anaconda distribution

I'm trying to run sphinx offline with mathjax. I'm using the anaconda distribution which runs ipython notebook with latex (mathjax I think) just fine.
I have sphinx.ext.mathjax in the extensions and everything works fine when I'm online. When I go offline the latex equations don't render.
I've added the following to try to get mathjax to use the one I think ipython notebook is using:
mathjax_path = 'C:\ProgramData\Anaconda3\Lib\site-packages\notebook\static\components\MathJax\MathJax.js'
I checked the path and it has a config/TeX-AMS-MML_HTMLorMML-full.js so I also tried:
mathjax_path = 'C:\ProgramData\Anaconda3\Lib\site-packages\notebook\static\components\MathJax\MathJax.js?config=TeX-AMS-MML_HTMLorMML-full'
Anyone have any idea how to get this to work from the mathjax provided in Anaconda?
===================================================================
Followup:
The following works for mathjax_path
mathjax_path = 'file://C:/ProgramData/Anaconda3/Lib/site-packages/notebook/static/components/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full.js'
Now mathjax doesn't render bmatrix correctly. The following only puts parenthesis by def, I need the parensthesis to extend the height of the full matrix.
.. math::
\mathbf{A_{X}} =
\begin{bmatrix}
abc \\
def \\
g h i \\
\end{bmatrix}
Setting mathjax_path to a file (default.js configuration) works Unfortunately the current anaconda package doesn't fully support rendering in sphinx. I downloaded mathjax and pointed there:
mathjax_path = 'file://C:/MathJax/MathJax.js?config=default.js'
https://github.com/sphinx-doc/sphinx/issues/4309
https://github.com/ContinuumIO/anaconda-issues/issues/8424

Generating custom legend (and only a legend) in matplotlib Python2

I'm trying to make a custom legend using matplotlib. The example in the matplotlib documentation doesn't work on my set up. Neither does this follow.
from matplotlib import pyplot as plt
import matplotlib.patches as mpatches
fig, ax = plt.subplots()
patch1 = mpatches.Patch(color='#a6cee3', label='Blue')
patch2 = mpatches.Patch(color='#1f78b4', label='Bluerish')
patch3 = mpatches.Patch(color='#33a02c', label='Greener')
patch4 = mpatches.Patch(color='#fdbf6f', label='Kind of orange')
patch5 = mpatches.Patch(color='#ff7f00', label='Orange')
all_handles = (patch1, patch2, patch3, patch4, patch5)
leg = ax.legend(all_handles)
ax.add_artist(leg)
plt.show()
How can I make it produce the desired legend?
I'm using Mac OSX 10.10.3, Python 2.7.6, Matplotlib 1.3.1.
Edit: #xnx's solution below works for Python 3, and works for Python 2.7.11 if using Matplotlib 2.1.1 (thanks #DavidG).
You should set the handles argument to ax.legend explicitly:
leg = ax.legend(handles=all_handles)
I think the issue with your code is that the first (positional) argument to legend is otherwise taken to be a sequence of objects you wish to label and you don't have any.
I had a similar issue.
This solved it for me:
leg = **plt**.legend(all_handles)

docpad-plugin-thumbnails appears to hang

Symptom...
docpad run results in the usual messages but it never gets past:
Currently on writeFiles at 45/45 100% =================================================
Environment -
osx 10.8.3
node v0.10.0
npm i.2.14
docpad 6.34.2
ImageMagick v6.8.5-3, which has been confirmed working from the command line
Steps to reproduce...
Install kitchensink skeleton (or the jade and adapt the coffeekup code in example)
Install docpad-plugin-associatedfiles
and docpad-plugin-thumbnails
Create an associate-files directory in Files and drop in another directory called 'gallery' with some .jpg's with no spaces in the filenames
Create a new page called gallery.html.coffee and cut and paste the coffeeKup example from thumbnails' read me file :) - see below.. [I've also tried simplifying it down to the bare functionality to show the thumbnails, by cutting out the checks on file-types and the links to the original sized images.]
docpad run and watch whilst it doesn't finish...
Observations -
If you remove the reference to getThumbnails and just list the associated files it all works peachy.
Filenames for the thumbnails that would be generated show up in the generated HTML file - but the thumbnails do not show up in the out directory (or anywhere else as far as I could find)
So questions...
am I missing the startlingly obvious? (here's hoping)
how do I inspect docpad.log?
I read the instructions for debugging, but so far I've not made sense of them enough to step into any code - sorry - I'm a real novice.
Thanks for any input,
The page looks like this:
---
layout: default
title: Gallery
---
image_exts = ['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG']
images = #getDocument().getAssociatedFiles().findAll({extension: $in: image_exts}).toJSON()
for image in images
a href: image.url, -> img src: #getThumbnail(image.url, w: 100, h: 100), alt: image.name
I had the same problem, and I used the command:
$ docpad --debug 7 run
If you get the error "spawn ENOENT", you must install graphicsmagick, because the gm library needs some configuration if you use imagemagick.
You can try this command:
npm install --save docpad-plugin-thumbnails
I was facing the similar issue and it worked for me.. hope this helps!
Did you configure the plugin to use imageMagick in your docpad.coffee?
plugins:
thumbnails:
imageMagick: true

Resources