I am using a package called microbiomeMarker to plot a cladogram (ggtree). It was taking too long to print so I implemented the Cairo package so that the printing is faster (there's a considerable change thankfully.
cladogram<-plot_cladogram(
OTU_lefse_res,
color = c("#7570B3","#D95F02"),
only_marker = TRUE,
branch_size = 0.2, #beyond this point everything is default values
alpha = 0.2,
node_size_scale = 1,
node_size_offset = 1,
clade_label_level = 4,
clade_label_font_size = 4,
annotation_shape = 22,
annotation_shape_size = 5,
group_legend_param = list(),
marker_legend_param = list()
)
ggsave(
filename = "16S_Marker_Cladogram.png",
units = "px",
dpi = 300,
type = "cairo-png"
)
My issue is that when it gets saved, the graph is zoomed in (as far as I can figure to the bottom right corner of the legend) so I can't see the cladogram. I've also tried saving it as a pdf, changing the dpi to 900, defining the size by pixels, setting in the ggplot "coord_fixed()"... I'm at a loss, I googled the issue but I can't find anyone having a similar issue. The example data of the package works fine. I've got about 10x the amount of data to be plotted, so I expect some delay, but I don't understand why I can't get it right.
If I don't set a printing device and just do:
plot_cladogram(
OTU_lefse_res,
color = c("#7570B3","#D95F02"),
only_marker = TRUE,
branch_size = 0.2,
alpha = 0.2,
node_size_scale = 1,
node_size_offset = 1,
clade_label_level = 4,
clade_label_font_size = 4,
annotation_shape = 22,
annotation_shape_size = 5,
group_legend_param = list(),
marker_legend_param = list()
)
I don't get any output in the plot window. Any ideas of something else I can try?
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
I'm having trouble changing the color of the bibliometric map using R. I intend to change the color to black and white. But I don't know the syntax used for that.
The code structure I use to generate the map looks like this:
conceptualStructure(M, field = "ID", method = "MCA", quali.supp = NULL, quanti.supp = NULL, minDegree = 2, clust = "auto", k.max = 5, stemming = FALSE, labelsize = 10, documents = 2, graph = TRUE)
Please help me, what code can I use to change the color of the map, background and text in my project.
I have never used conceptualStructure before, nor know what package it comes from (assuming it isn't base R), but I think you should be able to make it black and white by just specifying as such in the theme. E.g.
conceptualStructure(M,
field = "ID",
method = "MCA",
quali.supp = NULL,
quanti.supp = NULL,
minDegree = 2,
clust = "auto",
k.max = 5,
stemming = FALSE,
labelsize = 10,
documents = 2,
graph = TRUE) + theme_bw()
That may just be a ggplot2 thing though. In which case, i'm not sure I can help
I am new to Rstudio and have just plotted a network diagram using simpleNetwork in the networkD3 package. I am looking to save the output in PDF/JPEG/TIFF format for my PhD thesis, however, most suggestions are with respect to saving it on a website (.html).
My code is as follows:
simpleNetwork(data, Source = 1, Target = 2, height = NULL, width = NULL,
linkDistance = 120, charge = -40, fontSize = 12, fontFamily = "serif",
linkColour = "grey", nodeColour = "black", opacity = 1.0, zoom = F)
Everything runs successfully, however I am not able to save the output as a PDF/JPEG/TIFF.
Is there any way I could save it in a picture or pdf format?
Here is what I have done in the past using the 'htmlwidgets' and 'webshot' packages:
g <- simpleNetwork(data, Source = 1, Target = 2, height = NULL, width = NULL,
linkDistance = 120, charge = -40, fontSize = 12, fontFamily = "serif",
linkColour = "grey", nodeColour = "black", opacity = 1.0, zoom = F)
require(htmlwidgets)
saveWidget(g, file="name_of_your_file.html")
require(webshot)
webshot("file:///C:/Users/.../name_of_your_file.html", "name_of_your_pdf.pdf")
sometimes, a picture is worth a thousand words...
I am trying to follow help and Internet examples to create a very simple animation of a 3d-line in R. This is just a test and my final goal is to use this functionality to visually verify results of some geometrical transformations on 3d-movement data that I am analysing. So basically I need nothing more than a ‘3d-player’ interface that allows for usual interaction (rotation, zoom, play, stop, slide).
I figured out that rgl package does the job and I am able to use it for the sphere/points animation. But now I need to use it on lines and I get very strange results. In the example below there are 4 points and two lines (cyan and red) that connect the same points but the red line is for some reason in the ‘wrong’ place. The animation doesn’t make sense neither. Now, I am thinking may be it is impossible to do >> to animate more than one vertex with more than one attribute? But I don’t see this in documentation and obviously it is possible because line is animated! I spent quite a long time trying to figure out what is going on and will appreciate any help/advise/directions. many thanks
Ps: Tthe code below is a chunk in the markdown file and I am using Rstudio.
require(rgl)
require(rglwidget)
p11=c(0,0,0)
p21=c(50,50,0)
p12=c(50,0,0)
p22=c(10,50,50)
saveopts <- options(rgl.useNULL = TRUE)
did=list()
did[[1]]=plot3d(rbind(p11,p21,p12,p22), type="s", alpha = 1, lwd = 5, col = c('brown','darkgreen','orange','green'))
did[[2]]=spheres3d(c(100,100,100), alpha = 1, lwd = 5, col = "blue",radius=2)
did[[3]]=lines3d(rbind(p11,p21),lwd=8, col='cyan',alpha=.9)
did[[4]]=planes3d(0, 0, 1, 0, alpha=.4, col='green')
did[[5]]=lines3d(rbind(p11,p21),lwd=2, col='red')
aspect3d(1, 1, 1)
did[[6]]=grid3d(c("x-", "z-"),at = NULL,col = "gray",lwd = .5,lty = 1,n = 5)
sceneT = rglwidget(elementId = "plot3dT",width=500, height=300) #%>%
rgl.ids()
rgl.attrib(id=did[[3]],attrib = c(1:length(did[[3]])))
playwidget(sceneT,list(
vertexControl(values = rbind(c(0,0,0,0,0,0),c(50,50,50,50,50,50)),
vertices = 1:6, attributes = "z", objid = did[[4]], param = 1:2,interp =T),
vertexControl(values = r1,
vertices = 1:2, attributes = c('x',"y","z",'x',"y","z"), objid = did[[5]], param = 1:2,interp =T)),
start = 1, stop = 2, step = .1, precision = 3)
options(saveopts)
I am learning latex graphics. I generated latex graphs with standalone, but I am trying to generate R plots with latex fonts. Through online tutorials, here is my code with the Iris dataset in RStudio (I modified example code to get it working. Once I know how to fix the frame, I can study the code in more details):
library(tikzDevice)
options(tikzMetricPackages = c("\\usepackage[utf8]{inputenc}",
"\\usepackage[T1]{fontenc}", "\\usetikzlibrary{calc}",
"\\usepackage{amssymb}"))
## I need the amssymb package because I use \mathcal and \mathbb
tikz("formula.tex", width = 4, height = 4, standAlone = TRUE,
packages = c("\\usepackage{tikz}",
"\\usepackage[active,tightpage,psfixbb]{preview}",
"\\PreviewEnvironment{pgfpicture}",
"\\setlength\\PreviewBorder{0pt}",
"\\usepackage{amssymb}"))
par(mar = c(4, 4, 0.1, 0.1), mgp = c(2, 0.9, 0))
library(tikzDevice)
options(tikzMetricPackages = c("\\usepackage[utf8]{inputenc}",
"\\usepackage[T1]{fontenc}", "\\usetikzlibrary{calc}",
"\\usepackage{amssymb}"))
## I need the amssymb package because I use \mathcal and \mathbb
tikz("formula.tex", width = 4, height = 4, standAlone = TRUE,
packages = c("\\usepackage{tikz}",
"\\usepackage[active,tightpage,psfixbb]{preview}",
"\\PreviewEnvironment{pgfpicture}",
"\\setlength\\PreviewBorder{0pt}",
"\\usepackage{amssymb}"))
par(mar = c(4, 4, 0.1, 0.1), mgp = c(2, 0.9, 0))
plot(iris$Sepal.Length, iris$Sepal.Width, main="Iris sepal length vs width measurements", xlab="Length", ylab="Width")
dev.off()
tools::texi2pdf("formula.tex")
system(paste(getOption("pdfviewer"), "formula.pdf"))
Which gives me:
I would like to have a bit more white space on the right, so the 8 comes fully, and fix the title. The inner picture should be smaller and the title lower as well, if possible.
Sorry for this. I looked at the code and figured it out! I needed to remove
par(mar = c(4, 4, 0.1, 0.1), mgp = c(2, 0.9, 0))
which gives me:
So it works!!! :D