I want to create a R-plot that uses the font Latin Modern Roman and export it as pdf.
I've found the package extrafont that provides such additional fonts. At first, I had some issues with Ghostscript, which was not installed on my computer and after installation was not found. Providing R with the complete path to the .exe like this Sys.setenv(R_GSCMD = "C:/Program Files/gs/gs9.52/bin/gswin64.exe"), however, fixed the problem. Similar to many examples I've found on the internet, I then wrote the following script*:
require("extrafont")
loadfonts(device = "win")
dat <- data.frame(x = seq(1, 20), y = c(
1, 2, 4, 5, 7, 8, 9, 11, 21, 43, 30, 91, 100, 200, 238, 490, 700, 900, 920, 1000
))
file <- paste(fig_dir, "/test.pdf", sep = "")
pdf(file = file, width = 5, height = 5*0.75)
par(family = "LM Roman 10")
plot(x~y, data = dat, main = "LaTeX Font Plot", ylab = "y-lab", xlab = "This is the x-label")
dev.off()
embed_fonts(file = file, outfile = str_replace(file, ".pdf", "_embed.pdf"))
Here, fig_dir is the directory to a folder containing the exported figures.
The first problem is a warning message telling me that the width of symbol 0x2d is unknown. Nevertheless, the .pdf is exported. The main issue, however, is the subsequent embed_fonts() command, because it simply runs forever. Unfortunately, I won't get any error messages, I just never get a result. Maybe someone has a hint where the problem could be or even faced a similar problem?
*the fonts were previously installed:
font_import(prompt = FALSE, pattern = "lmroman")
loadfonts(device = dev)
Related
For 3D visualizaiton used matrix data. Package: Rayshader 0.34.0.
The data is can be seen in render_camera but using high_quality function facing problem in saving rendeeing out put.
Error in rayrender::obj_model(cache_filename, x = -bbox_center[1], y = -bbox_center[2], :
unused argument (texture = TRUE)
I was expecting a render image so that my 3d map can be saved in png format with rendering quality.
mat |>
height_shade(texture = textr) |>
plot_3d(heightmap = mat,
zscale = 1000,
solid = FALSE,
shadowdepth = 0)
render_camera(theta = -100, phi = 30, zoom = .7)
render_highquality("E:/URP/R/3D Bangladesh/DATA/Images/tp.png",
samples = 450,
preview = FALSE,
light = TRUE,
lightdirection = c(135, 45),
lightcolor = c("white"),
lightintensity = c(800),
ambient_light = 0.5,
shadow_intensity = 0.5,
zscale = 1,
width = 8000, height = 8000,
interactive = FALSE)
Install most recent dev versions of rayshader and rayrender.
remotes::install_github("https://github.com/tylermorganwall/rayshader")
remotes::install_github("https://github.com/tylermorganwall/rayrender")
Same issue.
I've tried to install the most recent dev versions but probably I do something wrong.
What do I have to choose here (and later similarly for rayrender)?
terminal options
If I choose "All" at every steps I get some conflicts
This is the first time I tried reactable and raising questions in stack overflow. I apologise in advance if anything is unclear.
I was working on a simple reactable, and while the preview in RStudio looks fine, when I tried to save it as png and html, 5 paragraph break symbol (pilcrow) appears on the top of the output.
This is a screenshot of preview in R Studio:
This is the actual output:
Not sure if it's related, but I got the below warning during output as well:
[WARNING] Deprecated: --self-contained. use --embed-resources --standalone
I tried others' reactable, and it produced the same paragraph break symbol in the html and png output.
Below are the codes I used:
# Libraries
library(dplyr)
library(ggplot2)
library(tidyr)
library(reactable)
library(reactablefmtr)
library(utf8)
library(gt)
library(htmlwidgets)
library(webshot2)
webshot::install_phantomjs()
# data
Rank <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Name <- c('Red Lion', 'Crown', 'Royal Oak', 'White Hart', 'Railway', 'Plough', 'Swan', 'White Horse', 'Kings Arm', 'Ship')
Number <- c(519, 485, 406, 300, 280, 278, 276, 271, 237, 230)
Popular_Pub_Name <- data.frame(Rank, Name, Number)
# reactable
table <- reactable(Popular_Pub_Name,
defaultSorted = "Number",
width = 500,
defaultColDef = colDef(align = "left"),
columns = list(
Rank = colDef(
width = 60
),
Name = colDef(
name = "Pub Name",
width = 100
),
Number = colDef(
defaultSortOrder = "desc",
width = 200,
cell = data_bars(Popular_Pub_Name,
fill_color="#7814ff",
text_position = "outside-end",
bar_height = 10,
text_size = 12,
min_value=0,
max_value =600,
background = "transparent"
)
)))
table1 <- table %>%
add_title("UK's Most Popular Pub Name"
)
# output
html <- "pub_name1.html"
saveWidget(table1, html)
# save as png
webshot(html, "pub_name1.png", zoom = 3, vwidth = 500)
I have installed fontawesome ttfs onto my local machine and loaded them into R. When I test this using fonts()[grep("Awesome", fonts())] it returns "FontAwesome" as expected.
I can run a waffle chart with certain glyphs... so far male, female, and briefcase have worked, but not others, such as "building."
Any idea what's going on?
library(ggplot2)
library(fontawesome)
library(extrafont)
library(waffle)
# This works fine
waffle(
c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
use_glyph = "female", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)
# This does not work
waffle(
c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
use_glyph = "building", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)
Not sure exactly why it is happening for some glyphs but not others, but I ran across the same issue recently. Found an excellent how-to here: https://www.listendata.com/2019/06/create-infographics-with-r.html
It sounds like you already have fonts available so could skip the first part of the how-to, and that you may just be missing packages. You'll want to add two others: echarts4r (on CRAN) and echarts4r.assets (on github only as of now)
require(devtools)
devtools::install_github("JohnCoene/echarts4r.assets")
library(tidyverse)
library(waffle)
library(extrafont)
library(echarts4r.assets)
library(echarts4r)
# Works for me with all of these packages loaded
waffle(
c(`Poor=10` =10, `Average=18` = 18, `Excellent=7` =7), rows = 5, colors = c("#FD6F6F", "#93FB98", "#D5D9DD"),
use_glyph = "building", glyph_size = 12 ,title = 'Girls Performance', legend_pos="bottom"
)
I am trying to create a Sankey Network for energy flow from data imported from excel sheets. I don't need it to be interactive and I think I have the code right. However, when I run the code in R Markdown it just creates a blank space - no diagram. Code as follows:
library(dplyr)
library(shiny)
library(htmlwidgets)
library(networkD3)
nodes = data.frame("name" = c(Energy$`Alberta Energy Flow in 2015: PJ`[2:11], Energy$...5[1], Energy$...6[1], Energy$...7[1], Energy$...8[1], Energy$...9[1], Energy$...10[1], Energy$...11[1],Energy$...2[13],Energy$...3[13] ), stringsAsFactors = FALSE)
links = as.data.frame(matrix(c(
0, 10, Energy$...5[2],
1, 10, Energy$...5[3],
2, 10, Energy$...5[4],
3, 10, Energy$...5[5],
4, 10, Energy$...5[6],
5, 10, Energy$...5[7],
6, 10, Energy$...5[8],
7, 10, Energy$...5[9],
8, 10, Energy$...5[10],
9, 10, Energy$...5[11],
0, 12, Energy$...7[2],
1, 12, Energy$...7[3],
#code continues as such for a while
byrow = TRUE, ncol = 3 ))
names(links)=c("source", "target", "value")
s <- sankeyNetwork(Links=links, Nodes=nodes, Source="source", Target="target",Value="value", NodeID="name", fontSize=12, nodeWidth=25 )
sankeyNetworkOutput("ABEnergy15.html", width = "500px", height = "1000px")
sankeyNetworkOutput() is used for Shiny apps, so you probably don't want to use that.
If you want to use it in RMarkdown, you probably want to add s to the last line of your code chunk, because that will tell R to "print" the s object which contians the htmlwidget that sankeyNetwork() created.
If you want to save it to a file, which it seems like based on your code having an html filename it, try using...
saveNetwork(s, "ABEnergy15.html")
Here is a very basic example:
library(vennerable)
srl.venn <- Venn(SetNames=c("Cognitive condition","Operations","Individual differences"),
Weight=c(0,30, 21, 15, 1, 8, 3, 6))
plot(srl.venn)
All I'm trying to do is to remove borders around circles, and format colors and fonts. However, still haven't done much.
Could you please share any useful examples?
Check out VennThemes for changing parameters within the plot. For example:
library(Vennerable)
srl.venn <- Venn(SetNames=c("Cognitive condition","Operations","Individual differences"),
Weight=c(0,30, 21, 15, 1, 8, 3, 6))
srl.venn.c <- compute.Venn(srl.venn, doWeights=T)
gp <- VennThemes(srl.venn.c, colourAlgorithm = "binary")
plot(srl.venn.c, gpList = gp, show = list(FaceText = "signature", SetLabels = FALSE,
Faces = FALSE, DarkMatter = FALSE))
More detail can be found in the man pages or by calling vignette("Venn")