Is there a way to avoid overlapping p axis labels? Have seen others suggest creating jitter, using direct.labels, etc., but have not found a way to make this work for radarchart{fmsb}
Would be fine with a general pointer toward a radarchart option or another function, but here is some reproducible code anyway:
library(fmsb)
MM<-data.frame(matrix(c(rep(1,35), rep(0,35),
runif(35, 0, 1), runif(35, 0, 1)), nrow=4, ncol=35, byrow=TRUE))
colnames(MM)<-rep('long variable name', 35)
colors_border=c( rgb(0,0,0,0.9), rgb(1,0,0,0.9))
colors_in=c( rgb(0,0,0,0.2), rgb(1,0,0,0.3))
radarchart(MM , axistype=1 ,
pcol=colors_border , pfcol=colors_in , plwd=2 , plty=1,
cglcol="grey", cglty=1, axislabcol="grey", cglwd=0.8,
caxislabels=c(0, 0.25, 0.5, 0.75, 1),
vlcex=0.8,
title='title',
na.itp=FALSE)
(Making the text smaller works, but that would be my last resort).
Related
I have generated a radarchart using the following code:
p3 <- radarchart(radar.plot, seg = 5, axislabcol = "grey", caxislabels = seq(0,50,5), pcol=colors_border,
pfcol=scales::alpha(colors_in, 0.5), plwd=2 , plty=1, cglcol = "black", cglty = 1, cglwd = 0.8)
It generates a preview of the plot that I can save in R.
However, I want to use the Cairo package to save in a much better quality.
The problem is that, while Cairo does give me a preview of the graph, I'm unable to save it using ggsave():
ggsave(filename = 'myfilename.tiff', dpi = 300, type = 'cairo',
width = 8, height = 4, units = 'in', path = "mypath")
Here is the mock data present in the radarchart tutorial if anyone wants to reproduce this issue:
# Library
library(fmsb)
# Create data: note in High school for Jonathan:
data <- as.data.frame(matrix( sample( 2:20 , 10 , replace=T) , ncol=10))
colnames(data) <- c("math" , "english" , "biology" , "music" , "R-coding", "data-viz" , "french" , "physic", "statistic", "sport" )
# To use the fmsb package, I have to add 2 lines to the dataframe: the max and min of each topic to show on the plot!
data <- rbind(rep(20,10) , rep(0,10) , data)
# Check your data, it has to look like this!
# head(data)
# Custom the radarChart !
radarchart( data , axistype=1 ,
#custom polygon
pcol=rgb(0.2,0.5,0.5,0.9) , pfcol=rgb(0.2,0.5,0.5,0.5) , plwd=4 ,
#custom the grid
cglcol="grey", cglty=1, axislabcol="grey", caxislabels=seq(0,20,5), cglwd=0.8,
#custom labels
vlcex=0.8
)
I think the issue lies in the fact that I cannot load the plot in a variable, as I usually do with my plot, here p3 returns NULL. The saved plot is the previously loaded plot, that is in fact loaded in p2 variable.
My guess is that the anwser is similar to the answer of this post: Why does ggplot not plot when storing to variable?
Does anyone have any idea how I can resolve or circumvent this issue?
Thank you.
I saw an answer from 2017 about using the following code to create a simple mediation flow per below using the diagram package. How can I add a box for a MODERATOR between the Mediator and Y path to this below?
THANK YOU in advance
data <- c(0, "'.56*'", 0,
0, 0, 0,
"'.64*'", "'.40* (.04)'")
M<- matrix (nrow=3, ncol=3, byrow = TRUE, data=data)
plot<- plotmat (M, pos=c(1,2),
name= c( "self.esteem","grades", "happiness"),
box.type = "rect", box.size = 0.13, box.prop=0.5, curve=0)
I am trying to plot a volcano plot in R using the plot function and calibrate package in R and am trying to use the textxy function to plot only certain points.
Here is some data:
Metabolites <- data.frame(Metabolite = c("Glucose", "Galactose", "Creatine", "Lactose", "N-Acetylputrescine", "Tyramine", "Adenine", "Glycine", "Erythritol", "Choline"), Neg_pvalue = c(10, 8, 2, 1, 0.5, 0.7, 5, 3, 5.8, 4), LogFC = c(4, -3, 2, -1, 0.5, 0.7, 1, -2, -4, -1), padjust = c(1.453557e-19, 5.312771e-08, 4.983176e-02, 9.585447e-01, 2.449707e-01, 3.058580e-01, 4.223173e-02, 1.002379e-03, 4.466316e-27, 1.003879e-01))
Here is my code:
with(Metabolites, plot(LogFC, Neg_pvalue, pch=20, main="CNL", xlim=c(-5,6)))
with(subset(Metabolites, padjust <.05 ), points(LogFC, Neg_pvalue, pch=20, col="blue"))`
with(subset(Metabolites, padjust <.05 & abs(LogFC) > 2), points(LogFC, Neg_pvalue, ph=20, col="red"))
Now here is the issue:
with(subset(Metabolites, padjust <.05 & abs(LogFC) > 2), textxy(LogFC, Neg_pvalue, labs=Metabolite[1:3], cex=.5, offset = 0.2))`
If I plot this code, I get only the top 3 data points, as is indicated with the labs=Metabolite[1:3] part of the code. Alternatively, if I plot labs=Metabolite, then I get all labels.
If I wanted to plot the labels of only: Glycine, Lactose, and Erythritol as given in the Metabolites$Metabolite, am I able to do this?
Also, say I wanted to keep my top 3 data points labeled (labs=Metabolite[1:3]), but also want to label other metabolites of interest, say Tyramine and N-Acetylputrescine too; how can I do this?
This seems to work by slecting items that are in that set and using those character values as lables:
library(calibrate)
with(subset(Metabolites, Metabolite %in% c( 'Glycine', 'Lactose', 'Erythritol' )),
textxy(LogFC, Neg_pvalue, labs=c( 'Glycine', 'Lactose', 'Erythritol' ), cex=.5, offset = 0.2))
I have a dataset that includes one point that is much higher in magnitude than the others; I am trying to use gap.plot to show this point on the graph without introducing unnecessary white-space. However, my line plot skips over the point in the top panel of the graph, leaving it isolated.
Code is as follows:
year<-c(2001:2015)
y<-c(30, 13, 0, 0, 0, 1, 5, 309, 7, 1, 58, 1, 62, 69, 49)
par(bty="n") #Deletes box
gap.plot(
year,y
, type="b"
, ylim=c(0,325)
, gap=c(100,275)
, gap.axis="y"
, xaxt = "n"
, xtics =NA
, xticlab=NA
, xlim =c(2001,2015)
, xlab="Year"
, ylab="Positive Samples"
, pch=15
)
axis(1,at=c(2001:2015))
abline(h=seq(100,103), col="white",lwd=5) #Eliminates horizontal lines
axis.break(axis=2,breakpos=100,style="slash")
I end up with the following graph:
What am I doing wrong?
I want to place 2 sets of y-axis labels on the graph I created using levelplot function from lattice library at R. I was able to get two sets of labels to show but they are overlapping. Below please see a minimum example. I also tried a few options at par.settings such as ylab.axis.padding and axis.components padding, but nothing seemed to change the superimposition of 2 y-labels. Perhaps they have been overwritten somehow? Any ideas will be appreciated.
My example codes :
A = matrix( c(3, 1, 0, 1, 2, 3, 1, 0,
rep(1,4), 2, 0, 1), nrow=3, ncol=5, byrow = TRUE)
colnames(A)= c("XXX5", "XXX4", "XXX3", "XXX2", "XXX1")
axis.build=function(side,...){
if(side == "left"){
panel.axis(side=side, outside=TRUE, at=1:5,tck=0,
text.col="black", labels=colnames(A), text.cex=0.5)
panel.axis(side=side, outside=TRUE, at=1:5,tck=0,
text.col="brown", labels=seq(ncol(A)), text.cex=0.9 )
} else axis.default(side=side, ...)
}
levelplot(A, aspect="iso", shrink = c(0.8, 0.8),
scales= list(x=list(draw=F),cex=0.5, font=2),
axis=axis.build,, xlab= NULL, ylab=NULL,
col.regions=c("black", "orange", "red","purple"),
at=c(-1, 0, 1, 2, 3), colorkey = FALSE,
par.settings = list(axis.line=list(col="transparent"),
axis.components=list(bottom=list(pad1=1, pad2=3)) ))
I think I have found the solution. In case anyone interested : I changed the first tck=0 to tck=2, and added line.col= "transparent", thus two left axis are stacked next to each other. Voila ! However, I can't seem to find where the documentation is for using pad1 and pad2 parameters. Any suggestion?