510,443 questions
Score of 0
1 answer
23 views
How do I get R plotly autorangeoptions clipmax and maxallowed to work
I want to combine the plotly autorange capability with a limit to the maximum range.
Setting the layout autorangeoptions attributes clipmax and maxallowed appear to be specifically for this purpose.
...
Score of 5
5 answers
179 views
How to unnest a list-column as new rows in pre-existing columns?
Context
I would like to efficientely add rows to a relatively large data frame (30 000+ line et 1.0+ Go). These rows are stored as tibbles in a in a list-column. I need to extract the content of each ...
Score of 1
1 answer
89 views
passing on geom_raster() breaks to geom_contour()
Is there a way to pass on the default geom_raster() breaks (e.g., 0.03, 0.02, 0.01) to geom_contour()?
library(ggplot2)
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density)) ...
Score of 0
1 answer
106 views
R.exe -e "source('./foo.R')" runs the script and immediately close the REPL session
To reproduce: create a file foo.R with the following content:
message("interactive = ", interactive())
and call it foo.R. Then, from Powershell, run the following command:
R.exe -e "...
Score of -4
1 answer
179 views
How can I convert an IP address to a country in R, and what are the recommended libraries?
For years I've been using rgeolocate in conjunction with Maxmind's free GeoLite IP geolocation dataset in MMDB format to convert IP addresses of website visitors to countries in R.
This is my current ...
Score of 5
2 answers
194 views
At least three digits before OR after the decimal separator with sprintf()
Is it possible to use sprintf() to format numbers so they display at least 3 digits before OR after the decimal point, as shown in the example?
68674.271 -> 68674
9863.683 -> 9864
387.961 -&...
Score of 3
1 answer
88 views
legendry nested axis compatibility while using geom_chicklet
I attempted to plot a geom_chicklet barplot with nested axis using legendry. I might have come across a small limitation of either two packages. Essentially, when flipping coordinates it isn't ...
Score of 0
1 answer
124 views
aggregate() changes classes
Here is a minimal reproducible example
> dummy_data <- data.frame(vec1= 1:10,
+ vec2= as.factor(1:10),
+ group= rep(letters[1:2], 5))
> str(...
Score of 2
3 answers
276 views
Find and remove the out-of-order numeric element in a vector
I am trying to find and remove numbers that are out-of-order in a number sequence in R. For example, in the following set of vectors, one or more elements are to be removed but sometimes it's unclear ...
Score of -3
1 answer
135 views
Why can't column be found? No ggplot2? [closed]
ggplot(data = dowell_raw, mapping = aes(x = factor(borh), y = bois)) +
fill = factor(borh) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitter(width = 0.1), color = "...
Score of 5
5 answers
182 views
Applying FUN in ave() to only a subset of the group
I want to apply a function, say mean, in the grouping function ave() to only a subset defined by a different column in the data set. Here is some toy data:
> x <- data.frame(A=c("a",&...
Score of 1
1 answer
71 views
Barplot is incomplete when combined with polar coordinates
I try to create a circular bar plot, however the first bar is being removed after applying coord_polar() . The following warning is being displayed:
Removed 1 row containing missing values or values ...
Score of 8
2 answers
1005 views
Error in .rs.exprMutatesPackageLibrary(expr) when adding paths to a data.table
When stepping through the below lines of code via RStudio (ctrl+enter) I'm getting the following error:
Error in .rs.exprMutatesPackageLibrary(expr) :
argument "part" is missing, with no ...
Score of 3
1 answer
83 views
patchwork collects fill guides but not size guides when using wrap_plots()
I have a function that is creating a bunch of plots and saving them in a list. When using patchwork::wrap_plots(), guides = "collect"collects the fill guide but not the size guide.
Expected ...
Score of -1
0 answers
78 views
SIMPROF will only run on certain subsets of my community matrix data
I am trying to evaluate significant differences in the community composition of various biomass samples. My original dataset included a column with sample names, a column with taxa names, and another ...
Score of 0
0 answers
52 views
How to Calculate Factor Scores After Regularized Exploratory Factor Analysis? [migrated]
I am doing some psychometric analysis of a measure. Based on parallel analysis and my own theoretical interpretation, it seems like extracting two factors is the ideal solution for this measure; ...
Score of -3
0 answers
133 views
Virtual environment manager for RStudio on Windows PC [closed]
For many years I've been using RStudio on my Windows machine. There is a complete mess of different versions of the R packages in the result. Because of that, installation of new R packages and their ...
Score of 0
1 answer
58 views
Selecting a specific timestamp for multiple layers in SpatRaster object
I am trying to find a computationally-efficient way to extract all layers with a specific timestamp in a SpatRaster in R, with the "terra" package.
My raster is a data cube downloaded from ...
Score of 1
2 answers
92 views
residuals.lrm is not in the rms R package where installed
I need to calculate some calibration metrics for a glm model. I've been recommended to use the Hosmer–Lemeshow test to check that my model is calibrated or not, but it seems like it's very criticized ...
Score of 1
0 answers
130 views
Trouble with fitting confirmatory factor models in R with lavaan [closed]
I am currently working on a scale development project. The scale is a measure of objective knowledge and therefore the variables are binary (0=incorrect answer, 1=correct answer). I want to compare a ...
Score of 1
1 answer
109 views
Add red shade/area for missing ranges to facet plot
I have a facet grid plot where I wish to add red-shaded rectangles/areas to categories for which I don't have any observations. I remember I achieved something similar with a much simpler 3×2 facet ...
Score of 2
1 answer
179 views
How to include plain text or markdown prose inside a reprex?
When creating a reproducible example using the {reprex} package, how can I include plain text explanations or markdown prose between my R code blocks without having them interpreted as standard R ...
Score of 2
2 answers
143 views
Dropping unused y values when using scale_x_datetime(limits =)
I have been looking for a solution to automatically drop unused y values when specifying limits in a ggplot2::scale_x_datetime() call, such as:
library(ggplot2)
ggplot(data=economics, aes(x=date, y=...
Score of 3
2 answers
113 views
geom_ribbon creating gaps / not filling-in all of area to be shaded?
I thought it'd be nice visually for a temperature time series to show all of the points at which the temperature was above a specific threshold. geom_ribbon doesn't seem to like to connect all of the ...
Score of 2
3 answers
262 views
How do I find which two values in a vector a value falls between, and extract the lower one?
I have a large range of dates (a) in a date-class that I need to find the nearest lower date in another, smaller, range (b), also in a date-class:
a <- c("2025-04-22", "2025-04-22&...
Score of 0
1 answer
79 views
ggplot in a for-loop with varying x-values [duplicate]
I have tried to build calibration plots for data frames with varying numbers and names of columns. So, I tried to work with this using lists and for-loops. Outside of the loop it works, but inside the ...
Score of 2
1 answer
103 views
Legend not correct in topr::locuszoom() plot
I am using the locuszoom() function from the topr R package. However, the legend, that is created automatically is not correct, as it doesn't show the legend for the dark blue color and the labels are ...
Score of 1
0 answers
127 views
Differences in results between terra::extract and exactextractr::exact_extract
I am extracting values from a raster based on a multipolygon layer. The polygons can overlap various raster cells or be wholly contained in one cell. I am interested in the sum of the value across the ...
Score of 3
2 answers
150 views
How to handle the ... parameter when programming with dplyr
If you are programming in dplyr, you can use the selection mechanism and promises as follows:
mypull <- function(data, var) {
data |> pull({{ var }})
}
then you can call for example iris |>...
Advice
1
vote
1
replies
114
views
Checking whether external pointer of a data.table is valid
I think this example speaks for itself:
tmp <- data.table::data.table(a = 1)
set_ <- function(x) data.table::set(x, j = "b", value = 2)
set_(tmp)
tmp # Is modified by reference, as ...
Score of 2
1 answer
71 views
Alter grouped column spacing to remove blank space in ggplot2
I'd like to display a grouped column plot for my dataset, where certain groups have subgroups associated with them. Here is a dummy dataset:
main_group <- c("Fruit", "Fruit", &...
Score of 0
1 answer
115 views
Shiny report generator: Rmd renders locally but not on shinyapps.io
I'm making a downloadable report which from a CSV input within a shiny app.
The app runs fine locally and generates an html report. However, upon publishing it to shinyapps.io, the report fails to ...
Score of 1
2 answers
198 views
Missing first month in bar chart using R and Rstudio
I created a bar chart for the month of January and February but the bar chart shows February and March. Any information in solving this problem would be greatly appreciated. Please find the code ...
Score of 2
2 answers
128 views
Moving annotation (tag) rightwards relative to default position
Given the following example:
library(patchwork)
p1 <- ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + geom_point()
p2 <- ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + geom_point()
...
Score of 1
0 answers
51 views
How does `avg_comparisons()` work for interaction models with individual and year fixed effects [migrated]
I have a question about avg_comparisons() with linear fixest models and individual/year fixed effects.
I ran this model
m <- feols(
y ~ treatment * sex | participant_id + year,
data = dat
)
...
Score of 2
1 answer
137 views
Convert str_c to str_glue
A practice question from https://aditya-dahiya.github.io/RfDS2solutions/Chapter15.html#tbl-q1a-ex5 asks us to:
# Convert the following expressions from str_c() to str_glue()
str_c("\\section{&...
Score of 2
1 answer
85 views
move legend in empty facet
I'm using facet_wrap2 to plot some data for different chromosomes. The thing is that I have some empty space beneath chr19 and chr20 and wish to move the legend there.
So, I was following this post ...
Score of 2
5 answers
152 views
Inserting single characters in data frame entries with ifelse
I have a data frame where I want to change entries to make sure that a numerical indicator at the end is two digits long, even if the recorded number is between 1 and 9. To illustrate, this is what we ...
Best practices
0
votes
3
replies
115
views
Interpreting correlation result obtained from R studio
I recently obtained correlation result for one of my datasets. I seek guidance to observe the computed result and interpret the correlation result to meet the requirement of report writing guideline ...
Score of 1
1 answer
144 views
future_invoke_map() deprecated, cannot get replacement to work
purrr and furrr have deprecated some of the functions I previously used to build ensemble machine learning models, namely future_invoke_map() which I used as as noted in the snippet below, this mapped ...
Best practices
1
vote
3
replies
88
views
From gt table in R-studio to an editable word file
I’m new to RStudio and have successfully created a gt table. However, I would like to export this table to a Word file (ideally in an editable format) while preserving its structure and formatting.
...
Best practices
0
votes
3
replies
129
views
Gap Statistic Versus Total Sum of Squares For Cluster Centres (r language)
Hi I had a quick question about what to do when you encounter a situation where the optimal cluster center is different when you graph out the gap statistic and the total sum of squares.
As I ...
Tooling
2
votes
11
replies
242
views
How to read a group of a .zarr file using R?
I want to use R to read a group from a .zarr file, which was originally created using python's xarray.
in python when I do:
import xarray as xr
path_zarr = "path/to/data.zarr"
ds = xr....
Score of 4
2 answers
230 views
Additional spaces and str2lang(x) error when creating formulas
I am currently trying to do calibrations for chemical data and have tried following the instructions given in this post. I can fully replicate the example and it works fine, but when applying it to my ...
Advice
6
votes
3
replies
389
views
What's the difference between the left curly brace and the right curly brace?
In the R documentation, it says:
Open parenthesis, (, and open brace, {, are .Primitive functions in R.
...
For {, the result of the last expression evaluated. This has the visibility of the last ...
Score of 0
1 answer
125 views
gtsummary treats continuous variable that has static values as categorical [duplicate]
I am using R 4.4.1 with gtsummary version 2.5.0. When a continuous variable has static values, gtsummary treats this as a categorical variable instead.
Example:
gtsummary::theme_gtsummary_compact()
...
Advice
0
votes
10
replies
107
views
Labelling GGPLOT Barchart with Two Variables
With the toy dataset below, I'd like to create a bar chart.
Each bar should be the description. The length of the bar should be the total length of days. But I'd also like the bar to have a total of ...
Advice
0
votes
6
replies
137
views
Is there a way to write images to google sheets from R?
I'm using the googlesheets4 package. I'm generating scatter plots and am trying to upload them to google sheets. I'm able to create the image and save it to my disk.
The code I've used so far is this:
...
Score of 1
1 answer
136 views
geom_text horizontal alignment in a dodged barplot
I'm working on a figure which upon suggestions was changed from a “stacked” to a “dodged” barplot. Everything seems to be working fine; however, the geom_text labels I added are now completely out of ...
Score of -3
0 answers
97 views
How to obtain and export a panelAR regression result?
Question update ; I am trying to summarize a panelAR model using modelsummarymodelsummary, which doesn't support panelAR models. I followed their instructions regarding unsupported models from this ...