I'm using Plotly (ggplotly) in my rmarkdown file. The width of the plot is larger than the content, see attached screenshot.
As you can see the legend is outside the content.
Can I fix this using CSS, if so, how?
I just found out that I had set a default fig.width and fig.height in knitr::opts_chunk() which caused this.
Related
I have an R blog post with some leaflet and plotly figures. I can set width = "100%" in the leaflet() function, and the leaflet map will change shape as I resize my browser window (or view on mobile). I've tried the same width = "100%" in plot_ly(), but the plot doesn't resize for smaller windows and requires horizontal scrolling.
Any ideas? I'm using blogdown/hugo if that is helpful.
Use the chunk option:
```{r, out.width='100%'}
Is it possible to change the size of the fa-icons in a a flexdashboard? The caption text overlaps with the icon and is even more of an issue when a numeric value is of the order 10^4 or greater.
It's not a huge issue but I think it will be more aesthetically pleasing if I can reduce the icon size somehow? I have tried to introduce a line break to the caption using \n but this does not work. I would rather reduce icon size than value size.
Screenshot attached. Thanks.
I have just used different icons instead. I have gone with narrower icons that do not overlap with any caption or value characters. Seems like the easiest solution for now.
Whenever I use captions in tables,
like
kable(df[1:10, c(7,1:6)], caption = "This is a caption")
the tables and content in the pdf generated by knitr are pushed below the limits of the bottom margin, thus becoming unreadable. Sometimes entire sections are missing, hidden off margins.
Also, plots positions go crazy: they are printed anywhere but the right place in the pdf.
using results="asis" in chunk options doesn't help.
Using pander causes the same problems.
If I remove all table captions and use some \newpage in the .rmd,
the pdf margins are fine.
Is there a safe way to use table captions?
The pdf in question is here: see page 14 for an entire section missing and table hiding in the bottom margins. Also, the plots are where they want, like if they had proper needs...
github repo
this is kind of a anti-climax,
but as it happens,
this problem was being caused by chunks that printed var values to the document, something like:
```{r}
sampled.values <- sample(1:100, 10)
sampled.values
```
when rendered through render(), this code chunk prints the value of sampled.values and this ruins the pdf pagination.
That's it: all page bottom margins are ok now that I removed all those var calls.
I'm trying to convert a R markdown .Rmd document to .pdf. Unfortunately, the images are too large. Is there any way to change the size of the image? I Can't use html, this is markdown to pdf.
Use this at the beginning of a chunk:
Decimals assigned to fig.height and fig.width are interpreted as inches. Other units of measure also allowed if explicit.
```{r, echo=FALSE, fig.height=2.7, fig.width=9}
#your R code here
```
I found a comfortable solution by the combination of fig.height, fig.width, dpi and out.width.
You can set global parameters at the top by:
knitr::opts_chunk$set(out.width="400px", dpi=120)
You can overwrite these properties in any chunk, just set the parameters you need.
dpi increases the quality image, so you have to adjust by the other parameters.
out.width adjust the size once the image is created.
Decreasing values in fig.height and fig.width will cause the text/numbers to be bigger (same as reducing image window in Rstudio)
There is a simple way to resize Images and still being able to add Captions. Use the following syntax within your RMarkdown code and place the Image's Caption beneath the Image:
<!-- Einbinden von Bildern in RMarkdown -->
\begin{figure}
\centerline{\includegraphics[width=0.5\textwidth]{your_image_name.png}}
\caption{Entitäten zur Persistierung der Special Notifications}
\end{figure}
To scale the image just adapt the width-value from 0.5 to some other percentage-value fitting your needs.
If you don't want to center the images, just remove the \centerline - Command with it's opening and closing brackets {}.
To the best of my knowledge rmarkdown html formats come with Bootstrap. I add the img-responsive with some javascript (at the bottom of my document).
<script>
var d = document.document.getElementsByTagName("img");
d.className += " img-responsive";
</script>
knitr offers helpful background shading for blocks of code. The resulting shaded panels are slightly wider than the rest of the text in an article. How can I get code panels with shading the same width as text sections? (You can see the extra width in the panels of code in Yihui's book.)