UNRAVEL_study %>%
group_by(sleep_dep) %>%
summarise(mean=mean(unravel), SD=sd(unravel), min=min(unravel), max=max(unravel), IQR=IQR(unravel))
how do I get a presentable table that gives me the same info as this code chunk? im trig to do a presentation for class and we can't show any code
Ok, this is how I fixed it:
UNRAVEL_study %>%
group_by(sleep_dep) %>%
summarise(mean=mean(unravel), SD=sd(unravel), min=min(unravel), max=max(unravel), IQR=IQR(unravel))%>%
kable(., caption = "sleep deprivation descriptive statistics")
I used the Kable function which makes it into a really tidy table. Then up top I added the directions echo=FALSE to not include the code, and message=FALSE to not include the R console
Related
I am trying to use the Export -> Copy to Clipboard option after making a kable() or gt() table. When I go to paste elsewhere, the clipboard image taken is a weird mix of my RStudio background with only part of the table. It is like my computer is clipping the wrong part of my screen. I have double checked and this does not happen when I try to do the same thing with ggplot(). I've attached my code as an example and what I receive as my output. I have instead been saving these plots as images (and this works fine!) but I really don't need these plots/just would like to copy them.
hectare <- PlantGrowth %>%
mutate(hectare = weight/10000)
partbtab <- hectare %>%
group_by(group) %>%
summarise("Mean/Yr" = mean(hectare),
"25 Year Average" = `Mean/Yr`*25)
kable(partbtab) %>%
kableExtra::kable_styling()
#this also does the weird screenshot
gt(partbtab)
This is what the copied "plot" ends up as:
I am using the huxtable package to create tables in a PDF rendered in bookdown. The table is formatted exactly the way I want it, up until I run the print_md command, after which a border is moved up row from underneath the column names to underneath the header. Also, the header is moved from a centered position to right-aligned. Check it out:
df <- data.frame(
"colname1" = c("something indicator"),
"colname2" = "[Something](http://www.overleaf.com)",
"colname3" = "[Something again](http://www.overleaf.com)")
df <- df %>%
as_hux() %>%
theme_basic() %>%
set_tb_padding(2)
df <- df %>%
set_contents(1, 2:3, c("colname2", "colname3")) %>%
insert_row("", "Header", "Header", after = 0) %>%
merge_cells(1, 2:3) %>%
set_align(1, everywhere, "center") %>%
set_tb_padding(1, everywhere, 0) %>%
set_bold(1, everywhere)
df
Which gives:
Table is formatted correctly. But. You'll notice that the URLs are not formatted correctly. It should only be showing the part within the brackets, which when clicked will take you to the site in parentheses.
This can be remedied with the following code:
df %>% print_md()
Which gives:
Now the URLs look like they should, but the border has erroneously moved up a row, and "Header" is now right-aligned instead of center-aligned. How do I stop that from happening?
Don't ask me why it works. But changing print_md() to set_markdown() fixed both the border and alignment problems.
EDIT: I'm adding #dash2's comment to this answer.
The reason print_md() was causing problems is because it converts the table to markdown format, which R Markdown then reads and produces a table from. So some features (alignment) get lost in translation. It'd be better to print the table in the intended output format, be it Latex, HTML or whatever you're using, instead of markdown.
But the cells with markdown hyperlinks need to be respected still - print_md() is just the wrong way to go about it. Instead, use set_markdown(). This will ensure that, within huxtable itself, cells with markdown code are interpreted as markdown before the table is printed. The printed table will then retain the intended format.
Thank you #dash2 for creating such a powerful package!
i'm trying to make my knitr tables (through KableExtra package) more appealing by adding some of the functions of the formattable package (i.e. colortile, ...).
But when running the code, the table gets visualized, but the table does not render the elements of the formattable. However I can see the HTML code in the table where the formattable functions would have to take place (6th column in the printscreen below):
This is my code to render the table:
input_file %>%
mutate(
month_perc = color_bar("lightgreen")(month_perc)) %>%
kable(format = 'html')%>%
kable_styling(bootstrap_options = c("hover","striped"))
Probably this is an easy fix, but does anyone have an idea why it doesn't render?
Thanks in advance!
Kind regards,
Simon
You need escape=F in your kable function.
If I have a chunk like
niris <- iris %>%
select(starts_with("Sepal"))
The knitr output of the chunk is
niris <- iris %>% select(starts_with("Sepal"))
But I would like it complies with the break lines of my code so it is printed in html as I print in code
. I was looking at R Markdown reference guide and at Yihui web and trying multiple options from Results and Code decoration and I couldn't get my goal.
Do you know how should I do?
Thank you!
You didn't provide a reproducible example, so I can only guess. You probably turned on the tidy option (i.e., you used the chunk option tidy = TRUE). If you did that, either set tidy = FALSE or just leave out tidy = TRUE since tidy = FALSE is the default.
The following error is shown in Rpresentation (From RStudio)
<!-htmlpreserve-> when rendering a tauchart on one of the presentation slides.
Whereas with ioslides there is no error and the graph is plotted nicely and keeps all its interactivity.
Do I need to add an additional parameter in the chunk options? Or do I need to specifically assign print to the object?
Code:
```{r,warning=FALSE,error=FALSE,message=FALSE,echo=FALSE}
tauchart(df) %>%
tau_stacked_bar(x="x",y="y",color="color") %>%
tau_legend() %>% tau_tooltip()
```