Legend in barplot R - r

I am trying to make a bar graph in R, but I have a permanent recurring problem. The legend appears wrong and I can't fix it.
If anyone knows how to fix it, I will be very grateful. I attach a screenshot from R:
Thanks!

I'm not sure what the exact issue is here since you posted a picture instead of a reproducible example, but the following code will give you the plot you want:
dev.off()
par(mai = c(1, 1, 1, 2))
barplot(table(cuestionario$genero),
main = "genero",
col = c("blue", "pink"),
ylab = "Cantidad",
ylim = c(0, 400),
beside = TRUE,
legend.text = TRUE,
args.legend = list(x = 3, y = 300))

Related

How to resize plot title in ggdensity()?

I thought this should be easy but I've been having a hard time trying to modify the title of each plot. I'm just new to R so I really don't know how to edit this.
As you can see in the image, all the plot labels are centered but not properly placed. Some letters were cut out of the frame. These labels are automatically generated by ggdensity() when I combine 2 columns in one plot.
bell_shape <- lapply(slash_k, function(x) ggdensity(x, c("Mean_Lesion_Height", "Mean_Max_Lesion_Length"),
combine = TRUE,
add = "mean",
fill = "lightblue",
x.text.angle = 360,
color = "darkblue"))
pen_bell_shape <- ggarrange(plotlist = bell_shape,
widths = 10,
heights = 10,
nrow = 2,
ncol = 3,
labels = c("3.IR20", "5.IR20", "7.IR20", "3.TN1", "5.TN1", "7.TN1"),
font.label = list(size = 9, color = "red"))
I really have no idea how to edit this. I hope someone can help me.
I tried
bell_shape + theme(axis.title.x.top = c(size = 1, color ="block")
But it returns NULL
The solution to this problem is using
theme(strip.text())
This question has already been answered here:
[https://stackoverflow.com/questions/3290330/facet-label-font-size]
[https://stackoverflow.com/questions/2751065/how-can-i-manipulate-the-strip-text-of-facet-grid-plots]
[https://stackoverflow.com/questions/2631780/r-ggplot2-can-i-set-the-plot-title-to-wrap-around-and-shrink-the-text-to-fit-t]
This is also a good alternative
[https://stackoverflow.com/questions/2631780/r-ggplot2-can-i-set-the-plot-title-to-wrap-around-and-shrink-the-text-to-fit-t]
This can also provide insghts
[https://stackoverflow.com/questions/37089052/r-ggplot2-facet-grid-how-include-math-expressions-in-few-not-all-labels]
And here is how to change the facet labels
[https://stackoverflow.com/questions/3472980/how-to-change-facet-labels]
Documentation here
[https://rpkgs.datanovia.com/ggpubr/reference/facet.html]

Change the size of labels in mosaic function, R

I have a mosaic, and I want to change the size of the character of the labels. What can I do?
library(vcd)
tbl<-structable(GWage~Gender,data=dat)
mosaic(tbl,shade=TRUE, legend=TRUE)
Updated for Mosaic()
mosaic(UCBAdmissions, sort = 3:1,
gp_varnames = gpar(fontsize = 14, fontface = 1),
gp_labels = gpar(fontsize = 10),
main = "Student admissions at UC Berkeley")
?labelings
See ?labelings & play around with the font sizes till you get what you want. You should probably post a tibble /mini-extract of your data to make it easily reproducible.
you may be able to do more with mosaicplot()?
Did you try
cex.axis = 0.7 # or whatever size works for your plot?
#Example:
table1 <- table(airquality$Temp[1:7], airquality$Month[1:7])
mosaicplot(table1,
main = "Example",
xlab = "Y",
ylab = "X",
las = 2,
border = "chocolate",
cex.axis = 0.7,
shade = TRUE)

Plot legend problems using R. Help removing excessive white space in legend box

I am creating a plot of some hydrology data and I am having trouble with the legend. The legend has a large amount of blank space around the text. I have tried using par(mar= list), cex, x.intersp, and anything else I could find with no luck. I can't post images yet, but there is a link below. This is all of the code I am using to create the plot and legend. The abline() below indicates the mean value of the data and that is what I am putting in the legend. I have researched on the site and I can make it work using mtext() or legend(no bg or box) and rect(), but it seems like I am missing something. I am fairly new to R, but I have written code in the past. I am using RStudio version 0.99.903 and R version 3.2.2.
plot(dataFile$time_s,dataFile$w_cmps, type = "l",col="grey50",
xlim = c(0,18.5), ylim = c(-7,7), xlab = "Time (s)", ylab = "w (cm/s)",
main = "Vertical Velocity", xaxt="n")
axis(side = 1, at = c(0,2,4,6,8,10,12,14,16,18),
labels = c(0,2,4,6,8,10,12,14,16,18))
abline(h = mean_w, col = "black", lty = 3, lwd = 4)
legend("bottomleft","Mean w", lty = 3, col = "red",
xjust = 1, cex = 1, bg = "grey75", trace = TRUE, ncol = 1, xpd = NA,
seg.len = 1, y.intersp = 0.25, x.intersp = 0.25)

VGAM percentile curve plot in R

I am running following code from help files of VGAM:
library(VGAM)
fit4 <- vgam(BMI ~ s(age, df = c(4, 2)), lms.bcn(zero = 1), data = bmi.nz, trace = TRUE)
qtplot(fit4, percentiles = c(5,50,90,99), main = "Quantiles", las = 1, xlim = c(15, 90), ylab = "BMI", lwd = 2, lcol = 4)
How can I just prevent putting points on the plot so that the graph shows only percentile curves? Is there some option in qtplot where I can suppress points on this graph, so that I do not need to resort to long ggplot route as done on this page: Percentiles from VGAM ? In my earlier question there were other issues also so this point got ignored. Thanks for your help.
There is no qtplot help page so I went to the package help Index and saw qtplot.lmscreg listed. It had a 'pcol.arg' to control points color so I set it to "transparent":
qtplot(fit4, percentiles = c(5,50,90,99), main = "Quantiles", las = 1,
xlim = c(15, 90), ylab = "BMI", lwd = 2, lcol = 4,
pcol.arg="transparent")

R plotting why not starting from (0,0)?

I'm new to R programming and graphics. I'm trying to draw a graph but the (0,0) point is not at the right place. Can someone please tell me how to fix it? Thanks.
Here's my code:
layout(matrix(c(0,0,0,0,0,
0,1,3,2,0,
0,0,0,0,0), nc = 5, byrow = TRUE),
widths = c(lcm(2), 1, lcm(2), 1, lcm(2)),
heights = c(lcm(2), 1, lcm(2)))
layout.show(3)
box("outer", lty = "dotted")
plot.new()
plot.window(xlim=c(-200,0),ylim=c(0,21))
box()
axis(1)
axis(4)
rect(-113,0,0,1,col='cyan')
you can go to see 'xaxs' in ?par

Resources