Likert plot 100 percent scale with Likert Package - r

I wanted to draw a likert plot with 100% scale (100) with equall plot size. I tried following code and give me following plot:
plot(LIKPR3,centred=TRUE,plot.percents=TRUE, plot.percent.neutral = TRUE, text.size = 6,
text.color = "black", include.center = TRUE,
ordered = TRUE, wrap = 60, wrap.grouping = 50, legend = "Response",
legend.position = "bottom", panel.arrange = "v",
plot.percent.low = FALSE, plot.percent.high = FALSE, central=FALSE)
I would like to make plot similar to following.
I am using "likert" package in R.
Any help is highly appreciated.

Hej,
the difference between the plot that you have created and the plot that you want to have is the "centre". With centered = TRUE you force the plot to be centred around the "neutral" category at 0, in case of a 5-point Likert scale this will be the third category. To obtain a stacked plot you have to use centered = FALSE.

Related

plot() won't change axis text size using cex.axis

I am trying to plot a likert scale of a 1 - 7 scale for every country with the likert package in R, but the R base plot() function won't change any of the text sizes (or even add a main title).
I am generating the plot with:
p <- likert(summary = data )
plot(p,
plot.percents=FALSE,
plot.percent.low=FALSE,
plot.percent.high=FALSE,
include.center=TRUE,
plot.percent.neutral = FALSE,
col = c(brewer.pal(n = 7, name = "RdBu")),
cex.axis = 0.5,
cex.lab=0.5,
main = "title")
Which produces the following plot:
Plot of Countries of the World
All the other plot parameters are working, so I'm not sure why the last 3, the most basic aren't working.
I fixed this by using theme(axis.text) like so:
plot(p,
plot.percents=FALSE,
plot.percent.low=FALSE,
plot.percent.high=FALSE,
include.center=TRUE,
plot.percent.neutral = FALSE,
col = c(brewer.pal(n = 7, name = "RdBu")),
main = "title") +
theme(axis.text=element_text(size=4)
This doesn't answer the larger question as to why the plot() function isn't accepting the parameters, as the title still isn't showing, but it's a band aid solution

Discrepancy in outputs between stars::st_contour() and graphics::contour in R

I have a raster object (link to file here) that plots contours 'wrong' in ggplot2 compared to base graphics.
Using ggplot2, the bottom area is missing the two 50% contour circles that are present in the base graphics plot. The total areas produced in the base graphics plot align to the calculated volume area sizes produced by the move::getVolumeUD(), which I'm inclined to trust/believe, and also align with the output generated using the fishtrack3d package: in terms of both calculated volume areas and UD contours.
library(magrittr)
library(ggplot2)
library(stars)
library(move)
test <- stars::read_stars(file.path("All_Rasters_Scaled_Weighted.asc")) %>% sf::st_set_crs(4326)
test %<>% starsExtra::trim2()
test <- as(test, "Raster")
test <- new(".UD", test)
is.na(test[[1]]) <- test[[1]] == 0
plot(test, xlab="location_long", ylab="location_lat", asp = 1)
contour(test, levels=c(.5, .95), col=c(6,2), add=TRUE, lwd=2)
That produces the following plot:
Obviously the asp ratio is different b/w contours and plot and looks ugly, but the key point is that it produces the 2 bottom 50% contour areas. This is like the plot produced by the fishtrack3d R package shown below:
Below is the ggplot code:
test <- stars::read_stars(file.path("All_Rasters_Scaled_Weighted.asc")) %>% sf::st_set_crs(4326)
contour1colour = "red" # colour for contour 1, typically 95%.
contour2colour = "orange"
legendtitle = "Percent UD Contours"
ggplot() +
geom_stars(data = test) +
ggplot2::geom_sf(data = stars::st_contour(x = test, contour_lines = TRUE, breaks = max(test[[1]], na.rm = TRUE) * 0.05), fill = NA, inherit.aes = FALSE,
ggplot2::aes(colour = "95% UD")) +
ggplot2::geom_sf(data = stars::st_contour(x = test, contour_lines = TRUE, breaks = max(test[[1]], na.rm = TRUE) * 0.5), fill = NA, inherit.aes = FALSE, ggplot2::aes(colour = "50% UD")) +
ggplot2::scale_colour_manual(name = legendtitle, values = c("50% UD" = contour2colour, "95% UD" = contour1colour))
which produces the following 'ugly' plot:
In this plot you can see that the bottom contours are absent. Given that the object is the same in both approaches, can anyone propose why the contour outputs are different?
Possibly relevant: in the ggplot2 approach we used 0.5 and 0.05 proportion of the object's max value as breaks values in st_contour(). In the base R approach, we set levels at 0.5 and 0.95. HOWEVER, the max value of this object is 0.008. According to the manual page for graphics::contour(), levels values seem like they should be absolute, rather than relative. Yet they behave as relative... or at least plot near identically to what we'd expect.
Thanks in advance for any help.

Quick question about transforming proportions to percentages - forest function in R

This forest plot is giving me proportions. How can I transform those proportions into percentages?
forest(meta.MAPO.Threshold, colgap.forest.left = "1cm", layout = "RevMan5", col.study = "black", comb.fixed = FALSE, xlim = c(0.00,1.00), digits = 3, cvar = SC.O, col.by = "black")
I tried the following suggested by another R post (https://stats.stackexchange.com/questions/123840/meta-analysis-transform-forest-graph-output-to-percentage-effect-in-r-metafor), but it didn't work. Edit: There's no error message when I use the below code. Unfortunately, there's no change to the units of the forest plot. That is, it's still showing me proportions, and not the percentages.
mytransf = function(x)
(x) * 100
forest(meta.MAPO.Threshold, colgap.forest.left = "1cm", layout = "RevMan5", col.study = "black", comb.fixed = FALSE, xlim = c(0.00,1.00), digits = 3, cvar = SC.O, col.by = "black",
atransf = mytransf)
Would greatly appreciate any pointers to reach the resolution!
Thank you.
Here's a link to a screenshot of what I currently have (it's all stated in proportions; I need to transform this into percentages):
Forest plot with proportions (need to change these into percentages!)

Can the shape of data points be changed according to group when plotting with Sjplot?

I am trying to optimize a sjPlot for black and white printing.
My plot looks at essentially numbers of parasites, depending on the amount of rain and is categorized by breeding status.
My data is broken up into groups of bachelor and breeder/territorial males.
While I can break up the prediction lines (GLMM pred models) into dashed and solid for the two groups when using "bw" for colors in the plot.model function, I cannot change the shape (or even grayscale color) of the raw data points for the two groups.
I can split the colors of the data points by group when using a different color scheme, but this distinction disappears with "bw" (all of the points are the same shade).
Key Takeaway: Is there a way to maintain a dashed and solid line distinction between two prediction lines (achieved using [colors="bw"]) and to either change the shape or color of raw data points by group in sjPlot? Thank you in advance!
I have tried using various additions to change shape; however, nothing has worked. Here are a few of the code additions to the plot that I have tried:
aes(shape=Reproductive_Status)
dot.shape="Reproductive_Status"
group="Reproductive_Status"....shape=group
Code: set up of the GlmmTMB model
strong.2.int.y<-glmmTMB(log.strongyle.
~ Rainfall_2MDelay*Reproductive_Status+age_y+(
1 | Animal_ID),data=parasites,na.action=na.exclude)
Code: plot; "aes(shape=Reproductive_Status)" does nothing to change point shape in this function unfortunately
test2.plot_strong.2.int.y.bw<-plot_model(strong.2.int.y, type ="pred", terms = c("Rainfall_2MDelay","Reproductive_Status"),
sort.est = NULL, rm.terms = NULL, group.terms = NULL, pred.type = "fe",
title = "(a)", axis.title = NULL, axis.labels = NULL, legend.title = NULL,
colors = "bw", show.intercept = FALSE, show.values = TRUE, show.p = F,
show.data = T, show.legend = TRUE, digits = 2, show.scatter=T,
dot.size = 2, dot.alpha=0.3,line.size = 1, vline.color = NULL,
aes(shape=Reproductive_Status))
+ labs(x=expression('Rainfall, R'[t-2]*' (mm)'),
y="Strongyle Count (log[x])")
+ theme(plot.title = element_text(hjust=0.0))
plot(test2.plot_strong.2.int.y.bw,add=TRUE)
For marginal effects plots (i.e. when type = "pred"), sjPlot simply calls functions from ggeffects. So if you're familiar with ggplot2, I suggest you use directly ggpredict(), which returns the underlying data that is needed for plotting.
You can also try ggeffects' plot()-method, and then try to customize it. There are two vignettes describing how to customize the plots:
Plotting Marginal Effects and Customize Plot Appearance.
Hope that helps.

R: tmap Legend Formatting

I am trying to create a function to map different variables for a specific state's school districts. However I a running into some problems formatting the legend. At the moment I have it laid out the best way to fit the maps(horizontally), but some of the text is being cut off (Below Average Poverty Rate), and I'd like to add % to the number labels in the legend. My code and an image of the legend is below. Any help you can provide would be very much appreciated. Thank You.
MakeLEAMap <-function(StateNum,NCHE_VAR,VAR1_NAME,In,Folder){
as.character(substitute(StateNum))
as.character(substitute(NCHE_VAR))
as.character(substitute(NCHE_In))
as.character(substitute(VAR1_NAME))
as.character(substitute(Folder))
map <-
tm_shape(LEA_1415_New[LEA_1415_New#data$STATEFP == StateNum, ]) +
tm_polygons(NCHE_VAR,border.col="#000000", lwd= .5, textNA="Below Average \nPoverty Rate" , palette = 'Blues', style="quantile",
title=paste(In," State LEA Map: ",VAR1_NAME),
legend.is.portrait = FALSE) +
tm_text("LCITY", size=NCHE_VAR,scale=.8, root=2,print.tiny = FALSE, size.lowerbound = .85, bg.alpha = .75,
remove.overlap = TRUE,legend.size.show = FALSE, col="black") +
tm_layout( legend.title.size = 3,
frame = FALSE, inner.margins = c(0,.0,.05,.0), asp = 1.5,
legend.text.size = 1,
legend.outside=TRUE, legend.outside.position = 'bottom',
legend.frame = TRUE,
legend.outside.size = .3, legend.position = c(-0.1, 0.3))
save_tmap(map, filename=paste("State_Maps_TEST/",Folder,"/",In,".pdf", sep = ''),width=8, height=8 )
}
MakeLEAMap("48","Abv_Diff_Home_Pov","% Children in Poverty minus \n% Children HCY (Ages5-17)",
"TX","ALL")
Here is what the legend looks like now
To make the legend show percentages use this function inside your tm_polygons call:
legend.format=list(fun=function(x) paste0(formatC(x, digits=0, format="f"), " %"))
You can play with the digits (decimal points) and you can drop the space before % sign if you desire.
To make the legend more legible increase the space around your map by making a bigger bbox (possibly using extent function from raster package to read bbox of your spatial object and then enlarging it) and move the legend by adjusting its position.
This is what I came up with in a different context, but one which also called for a percentage sign in tmap legend.

Resources