Skip to main content
The 2025 Annual Developer Survey is live — take the Survey today!

R Language Collective

Questions

Browse questions with relevant R Language tags

6,348 questions

Has recommended answer
3 votes
1 answer
54 views

How to format numbers with commas using table1

How can I format table1 columns with comma format? The sample data below has fewer rows and it does not display big values that require commas because I can't post my huge dataset. I wonder if someone ...
Salvador's user avatar
  • 1,797
Answer Accepted

library(table1) set.seed(42) dat <- data.frame( Group = factor(rep(c("Treatment", "Control"), each = 50000)), Count = round(rnorm(100000, 50, 15)), Category = ...

View answer
M--'s user avatar
  • 30k
1 vote
1 answer
67 views

How to correctly read German special characters from CSV file in R on Linux?

I am trying to load a German CSV file into R on Fedora Linux 42, but the region names containing special characters (like u-umlaut, o-umlaut, eszett) are not rendered correctly. Here's a simplified ...
Saïd Maanan's user avatar
Answer Accepted

Looking at the file, it is incorrectly encoded. It does satisfy the requirements for looking like a UTF-8 file, but it doesn't encode the characters you are expecting. For example, in Nürnberg, the &...

View answer
MrFlick's user avatar
  • 208k
1 vote
2 answers
85 views

Persist R function defined in Rprofile even if user clears environment

I have an rprofile that is used for multiple users spinning up sessions in a shared jupyterhub. In it I define a function that sets some parameters for closing out idle sessions (basically it ...
lilyrobin's user avatar
Answer Accepted

Edit: changed from using rlang::env_unlock() (which is deprecated) to something more local. Somes notes about this: I'm using dot-names, mostly because it is one-step more to "find" them ...

View answer
r2evans's user avatar
  • 164k
1 vote
2 answers
53 views

Creating (ggplot2-)boxplots based on integer x values with correct spacing on the x axis

I am trying to visualize my benchmarking results where for three values of the discrete hyperparameter p and two values of categorical hyperparameter q, I have 50 runtimes. I am trying to create a ...
David Köhler's user avatar
Answer Accepted

A pure {ggplot2} option would be to convert your p column to integers and to explicitly set the group aes to group by both p and q: library(ggplot2) set.seed(123) min_ex <- data.frame( p = ...

View answer
stefan's user avatar
  • 128k
0 votes
4 answers
113 views

Plotting actual words as the bars in R

I have a list of text: 1996 Steven Harper - Immunopathogenesis of IgA nephropathy 1997 Nigel Brunskill - Pathogenic implications of proteinuria 1998 Albert Ong - Polycystic kidney disease 1999 ...
tacrolimus's user avatar
Answer

Yet another ggplot option, if you want your labels to sit inside actual bars: library(tidyverse) df %>% mutate(nchar = nchar(Title)) %>% ggplot(aes(Year, 0)) + geom_label(aes(label = ...

View answer
Allan Cameron's user avatar
3 votes
1 answer
77 views

Select and deselect an entire group of choices on a pickerInput from shinyWidgets

I am aware that there is a similar question that was answered pre 2023, but the internal structure of pickerInput has changed since. - Old Fix I will also use the same reproducible example that was ...
user30669325's user avatar
Answer

In the original solution in the other thread, event listeners "piled up" with no clean-up, which was breaking the functionality. Here, I am using .off() to remove duplicate event handlers ...

View answer
M--'s user avatar
  • 30k
2 votes
1 answer
65 views

issue in MLE of New Generalized Poisson lindley Distribution

I am working with the New Generalized Poisson Lindley (NGPL) distribution, which is a two-parameter discrete distribution defined by parameters α (alpha) and β (beta). I wrote an R function to ...
Abdul Malik's user avatar
Answer

The problem is for your pmf to be valid, alpha and beta need to be constrained. As I understand it from the original paper, alpha needs to be > 1 and beta needs to be > 0. If these constraints ...

View answer
Allan Cameron's user avatar
1 vote
1 answer
102 views

Usage of options(warn=2) and tryCatch() with purrr R library

I am most likely not doing the right thing below, why do I get different answers? library(furrr) fu=function(x){ options(warn=2) b=x tryCatch({b=as.numeric('b')},error=function(e){}) options(...
S.T.'s user avatar
  • 23
Answer Accepted

Up front: This is an "inadvertent feature" of future, and may not be avoidable without some (not insignificant) code-inspection and inference. (I also think it has nothing to do with furrr ...

View answer
r2evans's user avatar
  • 164k
0 votes
1 answer
55 views

Plotly Returning a Blank Plot? [closed]

I've been trying to plot some growth rate data using plotly's 3d surface function: library(plotly) library(htmlwidgets) data <- data.frame(Msp1) plot <- plot_ly(data = Msp1, x = ~Msp1$Pressure, ...
marshmelow's user avatar
Answer

The issue is the setup of your data, i.e. your data is organized as a data.frame whereas a Plotly surface plot requires a matrix. Hence, to fix your issue you should convert your data to a matrix: ...

View answer
stefan's user avatar
  • 128k
2 votes
2 answers
57 views

In ggplot2 facet grid with distinct start x-axis scale

I’m trying to display two side-by-side bar charts to demonstrate how truncating the x-axis distorts the viewer’s perception of the data. The left chart correctly runs from 0–850 m, but I can’t seem to ...
Laura's user avatar
  • 671
Answer

The use of patchwork in @GregorThomas's answer is my usual first-attempt, and it works well. Another method is to use ggh4x::facetted_pos_scales to define the x-axis individually for each facet: ...

View answer
r2evans's user avatar
  • 164k
4 votes
3 answers
95 views

How can I change the color of censor points on a ggsurvplot?

Censor points are very difficult to distinguish from the survival curve they're placed along when the colors match, which they do by default. I'd like to change the color of censor points on my plot, ...
Garrett Foster's user avatar
Answer

Here's another method by drawing the points after creating the ggsurvplot: library(survival) library(survminer) ggsurvplot( survfit(Surv(time, status) ~ sex, data = lung), data = lung, censor....

View answer
M--'s user avatar
  • 30k
0 votes
1 answer
39 views

how contain setCalendar() in qlcal to the scope of a function?

In the package qlcal which "brings the calendaring functionality from the QuantLib project to R", how can we avoid changing the global calendar when calling `setCalendar() within a function? ...
mac's user avatar
  • 3,606
Answer Accepted

The package doesn't seem to support that scenario, but you can use the base R on.exit() to reset values when your function exits. You can use isHolidayInCal <- function(date, calendar){ ...

View answer
MrFlick's user avatar
  • 208k
7 votes
3 answers
274 views

Corrplot top labels distance

I am using corrplot library to plot correlation matrices in this manner : library(corrplot) car_matrix <- cor(mtcars, use = "pairwise.complete.obs", method = "pearson") png(&...
chiliconcarno's user avatar
Answer Accepted

You could add a break to each name of the matrix to add some space like this: data("mtcars") library(corrplot) library(RColorBrewer) car_matrix <- cor(mtcars, use = "pairwise....

View answer
Quinten's user avatar
  • 42.2k
0 votes
1 answer
43 views

How to access data in json downloaded via API

I accessed climatetrace.org via API . I used R environment. I could download the JSON format. url <- "https://api.climatetrace.org/v6/assets/emissions" req <- request(url) resp <- ...
OJH's user avatar
  • 1
Answer

When you look at the basic structure, str(resp_body_json(resp)) # List of 1 # $ USA:List of 62 # ..$ :List of 7 # .. ..$ AssetCount: int 0 # .. ..$ Emissions : int 0 # .. ..$ Year : NULL ...

View answer
r2evans's user avatar
  • 164k
7 votes
4 answers
382 views

How to plot iterating over rows in R

I am trying to plot two Y values row by row onto the same plot. Here is an example dataset (5 rows): T0 <- c(1842,2047,1831,2627,1769) T3 <- c(13842,6847,4480,15873,17163) test <- data.frame(...
user95146's user avatar
  • 400
Answer

As you mention iterate row by row, we can plot every row one at a time with gganimate: library(gganimate) X$rn <- seq(nrow(X)) p <- ggplot(X, aes(x = 0, xend = 1, y = T0, yend = T3, colour = ...

View answer
zx8754's user avatar
  • 56.5k
-1 votes
1 answer
55 views

Multiple Regression Especification in one Plots [closed]

I'd like to make a plot like in R But, I have no idea how to do it. Can some of you help me? The plot shows the coefficients and Confidence intervals for several regressions and each specification ...
Andres Rengifo's user avatar
Answer Accepted

This looks like a customized type of upset plot. Without knowing your starting point, it's very difficult to give concrete advice. However, we may show an example of how you could go about creating ...

View answer
Allan Cameron's user avatar
-2 votes
2 answers
82 views

How to program a dispersion graph? [closed]

I need a distribution graph so I can see how my data is on a graph. I need one plot that every dot is a person from my data. I need to use ggplot2 and a simple version for a beginner. I have a data of ...
user26842578's user avatar
Answer

If I understand you correctly, you have a variable called sdq which is presumably a numeric score between 0 and 25. You also have a variable called adhd which is a character vector of "yes" ...

View answer
Allan Cameron's user avatar
0 votes
1 answer
46 views

Generating a flexdashboard with plotly plots in a for loop but unable to get desired result when accessing elements in a list of tagLists in a loop

I'm trying to write this RMarkdown file that generates a dashboard using flexdashboard, with interactive plots via plotly, using a for loop to generate the appropriate RMarkdown code (e.g. using cat(...
user30495141's user avatar
Answer Accepted

As you did not provide a working or runnable example one can only guess what's the issue with your code. Below is a minimal working example base on the mtcars dataset which uses a nested for loop to ...

View answer
stefan's user avatar
  • 128k
1 vote
3 answers
86 views

What is the R equivalent to Python's ZipFile.writestr

In a Python script, I have: import zipfile mytext='abcdefghijklmnopqrstuvwxyz' zip=zipfile.ZipFile('filename.zip','a') zip.writestr('a.txt',mytext,zipfile.ZIP_DEFLATED) I have several python scripts ...
kevin's user avatar
  • 21
Answer

I am not aware of an exact equivalent of ZipFile(..., 'a'). There is zip::zip_append, but you need to write your mytext to a file (temporarily) before appending it. library(zip) mytext <- "...

View answer
M--'s user avatar
  • 30k
7 votes
6 answers
311 views

Use R to visualize activities across 24 hours as a pi chart 'clock' or bar

For fun, I would like to track the time when a baby is sleeping or feeding over the course of 24 hours and then visualize this as a pi chart or polar chart so that it resembles a 24-hour clock. Every ...
user3710004's user avatar
Answer

I suppose it's just for fun, but why not show a whole week's worth using a spiral track? Create a little helper function and a data frame of the week: posix_to_mins <- function(x) difftime(x, as....

View answer
Allan Cameron's user avatar
2 votes
1 answer
54 views

Customizing legend when plotting plotting geom_spatraster and geom_spatvector in R

Using R, I am attempting to create a plot that contains both geom_spatraster and geom_spatvector objects, and I am running into issues with the legend. Using the repex at the bottom below, the legend ...
KAR's user avatar
  • 37
Answer Accepted

To get a separate legend map on the shape aesthetic instead of setting the shape as a parameter and use e.g. scale_shape_identity. Additionally I explicitly set the order of the legends via ...

View answer
stefan's user avatar
  • 128k
3 votes
2 answers
76 views

Order bars within stacked barchart by value in plotly R

I would like to order the values within a stacked barchart by its value using plotly. This means that for each stacked bar the highest value should be the first bar. Here is a simple reproducible ...
Quinten's user avatar
  • 42.2k
Answer

We could use geom_rect to imitate stacked bar chart. Adapt colours, xaxis labels as needed, and convert to plotly. data <- data %>% ungroup() %>% mutate(xmin = as.numeric(as.factor(...

View answer
zx8754's user avatar
  • 56.5k
2 votes
1 answer
92 views

How to get the same results using`rpois` and `rpoispp` from spatstat [closed]

I'm struggling using the functions rpois and rpoispp from the spatstat package, specifically when using lambda as a pixel image object. I want to sample points from certain pixels using lambda, but to ...
Florencia Grattarola's user avatar
Answer Accepted

The docs for rpoispp specifically say: warning Note that lambda is the intensity, that is, the expected number of points per unit area. The total number of points in the simulated pattern will be ...

View answer
Allan Cameron's user avatar
2 votes
1 answer
62 views

Set operations with selection helpers

I'm trying to select only certain variables to display as single row within a tbl_regression. The current result is I was using the simple input below: database = data.frame( INDIV_AGE = rnorm(100, ...
Sigil's user avatar
  • 47
Answer Accepted

If I undestand your question correctly, you can achieve your desired using all_dichotomous() & !"PAIN_SCALE", i.e. instead of a set operation we have to use a boolean operation in a tidy ...

View answer
stefan's user avatar
  • 128k
3 votes
1 answer
56 views

geom_text - concatenate stat and variable in the label [duplicate]

In a ggplot (a bar plot in this example but I guess the same question applies to any plot), I would like to add a label composed of a stat computed by ggplot and the associated variable value but I ...
Tom's user avatar
  • 453
Answer Accepted

When you apply a stat the original data gets transformed and the original columns and column names are no longer available or present in the transformed data. But as you map trans on the fill aes the ...

View answer
stefan's user avatar
  • 128k
2 votes
3 answers
91 views

How to properly combine two ggplots and properly align axis and strips/titles?

I need to combine two ggplots. They should have labels (A, B, and C) as for being used in a publication. The first plot is a facet_wrap(). This is my code: library(ggplot2) library(dplyr) library(...
Giuseppe Petri's user avatar
Answer Answer recommended by R Language Collective

patchwork's free() lets you remove the alignment, so you could do (free( p1 + ylim(0, 6) ) | free( p2 + ylim(0, 6) + theme_bw() )) & theme( plot.title = element_text( hjust = ...

View answer
Michiel Duvekot's user avatar
2 votes
1 answer
80 views

Move Facet label to the left to make space for legend [duplicate]

I am using facet_wrap and need to move the x axis table left and the y2 axis lable up to make room for my legend and was wondering if the is possible. Below is my code and an image of what I am trying ...
Savy's user avatar
  • 45
Answer Accepted

As started by @Edward's comment, use axis.title.* theme arguments. ggplot(mtcars, aes(mpg, disp)) + facet_wrap(cyl ~ ., ncol = 2) + geom_point(aes(color = factor(gear))) + scale_y_continuous(sec....

View answer
r2evans's user avatar
  • 164k
1 vote
2 answers
65 views

How to extract tables hierarchically (grouping by title) on a website using rvest?

A website 'https://www.environnement.gouv.qc.ca/eau/potable/distribution/resultats.asp', stores the data in 3 different tables : 1. region, 2. mrc and 3. reseau. Essentially, I'm trying to extract the ...
M. Beausoleil's user avatar
Answer Accepted

The logic and code to scrape every webpage is going to be somewhat different and there's no guarantee the HTML structure won't change in the future. In order to scrape a page, you're going to have to ...

View answer
MrFlick's user avatar
  • 208k
2 votes
1 answer
115 views

How do I parse text from my front-end into R?

I'm building a Vue app that uses R for the back-end. I was able to successfully pull in data from a form into R. I'm using the plumber library. However, I don't know how to parse text. Here is the R ...
Priya Patel's user avatar
Answer

#* @post /api/generate-graph function(req, res) { # uploaded file and fields file_info <- req$files$file graphType <- req$body$graphType xAxis <- req$body$xAxis yAxis <- req$...

View answer
M--'s user avatar
  • 30k
3 votes
2 answers
148 views

How can I calculate the number of local maxima in a 3D matrix in R?

I am currently working on a number of animal teeth stored as surface meshes in R. Some of the variables I am looking at may be influenced by the number of cusps on the tooth and I would like to try ...
user2352714's user avatar
Answer

The question implies data is in the format of a 3D mesh, like molaR::Hills. It seems to me that the simplest way forward is to convert the mesh into a 2D raster. We can do this by using the vertex co-...

View answer
Allan Cameron's user avatar
1 vote
1 answer
55 views

Adjust axis label placement on ggcorrplot

How can I get the y-axis label to plot next to the correlation square? The default is to place all labels on the same axis however, I would like them to be offset. The script below has the y-axis ...
tassones's user avatar
  • 1,838
Answer Accepted

You can turn off the y axis labels and add a geom_text layer containing calculated label positions from your correlation matrix. It also requires turning clipping off: library(tidyverse) library(...

View answer
Allan Cameron's user avatar
3 votes
1 answer
110 views

Warning messages with plotting density lines on top of histrogram in R

I am trying to display that the chisquared distribution goes to the normal as the df increases. I have the following code: dfs <- NULL df.vals <- NULL for (i in 1:4) { df.vals <- c(df....
user3236841's user avatar
  • 1,366
Answer Accepted

The reason you are getting the warnings is that you are specifying the data and mapping arguments in the initial ggplot() call, which means each layer inherits your data frame and mapping. Since ...

View answer
Allan Cameron's user avatar
0 votes
2 answers
42 views

Adding horizontal line the fill part of the width for categorical x-axis

Below is a bar plot library(ggplot) g <- ggplot(mpg, aes(class)) g + geom_bar() How can I create a horizontal line at y = 20, that will occupy middle 70% of the plot width? A related method ...
Bogaso's user avatar
  • 3,500
Answer Accepted

You can avoid the need for explicit user-space calculations by using the I() notation to represent npc co-ordinates since ggplot v3.5.0. To get a line spanning the middle 70% we just need x = I(c(0.15,...

View answer
Allan Cameron's user avatar
0 votes
1 answer
55 views

Adding normal density plot to histogram in ggplot - A follow up question [closed]

This is a follow up question to the accepted answer of my original post Adding normal density plot to histogram in ggplot. In that answer, I found that the "normal distribution probability plot&...
Bogaso's user avatar
  • 3,500
Answer Accepted

Up front, the error and warnings: Error in geom_line(aes(x = dat[dat$met == "Metric2", ]$val %>% { : Problem while computing aesthetics. ℹ Error occurred in the 4th layer. Caused by ...

View answer
r2evans's user avatar
  • 164k
1 vote
1 answer
57 views

Create a string from data in a dataframe column in R

I have a dataset which I am trying to validate. I created a column that contains the written rules for what to check for each row and would like to use paste0 to concatenate the data in that column ...
user30397791's user avatar
Answer Accepted

The documentation might be a little misleading. It says Usage: validator(..., .file, .data) Arguments: ...: A comma-separated list of validating expressions .file: (optional) A ...

View answer
r2evans's user avatar
  • 164k
0 votes
1 answer
92 views

Why does `tapply` give a different result depending on the parameter of FUN

I am working on data analysis and came across the following. Given a triplet data frame, consisting of indices i, j and value v, create a matrix m[i, j] = v. A matrix element can have multiple values. ...
clp's user avatar
  • 1,592
Answer Accepted

When FUN= returns a scalar for all calls, then the default of simplify=TRUE means that it is turned into a vector, non-indexed positions are assigned NA as an indicator of missingness, and this vector ...

View answer
r2evans's user avatar
  • 164k
3 votes
1 answer
93 views

How can I set "cr" as the default basis type in mgcv::gam instead of "tp"?

I'm using the mgcv package in R to build generalized additive models (GAMs), and I often use cubic regression splines (cr) instead of the default thin plate regression splines (tp) (mainly because cr ...
Tripartio's user avatar
  • 2,373
Answer Accepted

The function s is defined with bs = "tp" as a default argument. There aren't any settings anywhere that can change this. Furthermore, you can't even define a wrapper of s because of how gam ...

View answer
Allan Cameron's user avatar
2 votes
4 answers
123 views

How to functionalize base R function like `with()`?

I am trying to write a function that operates similarly to with() where the function has a data argument, and two other arguments that I would like evaluated in the context of the data frame. I ...
Daniel D. Sjoberg's user avatar
Answer Accepted

You are on the right track with rlang::inject(). But note that the documentation states that You can use {{ arg }} with functions documented to support quosures. Otherwise, use !!enexpr(arg). So let’...

View answer
Konrad Rudolph's user avatar
0 votes
1 answer
46 views

re-order factors on y axis of a gantt chart

I am trying to produce a Gantt chart with the locations on the y axis in alphabetical order but nothing I tried worked out. Here is the code: gantt <- read_excel("2025-05-07_gantt_chart.xlsx&...
Fiona's user avatar
  • 25
Answer Accepted

The y axis is in alphabetical order, but factor ordering is such that earlier letters in the alphabet get the lowest values, so when these are plotted they are lower on the y axis. Therefore the order ...

View answer
Allan Cameron's user avatar
1 vote
1 answer
46 views

How to write multiple named sheets to excel workbook using openxlsx

I need to use the openxlsx library due to java issues at my institution. I have a list of dataframes called data_list that are simply named 1, 2, 3, etc. > data_list $`1` Count TaxID ...
aminards's user avatar
  • 459
Answer Accepted

You said you needed to use openxlsx because of issues with java, have you tried writexl? Perhaps something like this: strsplit(file_list, "_") |> sapply(function(st) paste(st[1:4], ...

View answer
r2evans's user avatar
  • 164k
1 vote
1 answer
96 views

Adding custom HTML before <div class="main-container">

I am using the includes options in R Markdown to add custom CSS and HTML to my document. My main goal is to add a banner to the top and a pretty background (not the one in the example) to the body of ...
Sobo's user avatar
  • 125
Answer Accepted

I think we can fix this with a little more css: body { background: url(https://linesteppers.com/tutorials/RMarkdown/img/BannerImage_TreeBlossoms_4470x3024.jpg); /* remove margin and padding */ ...

View answer
M--'s user avatar
  • 30k
1 vote
1 answer
52 views

Color edge links in ggraph based on specific nodes

I am trying to generate a bipartite graph where I color specific links based on certain nodes (i.e., plant species names). So far, I have been able to color the nodes of interest, but not their ...
J. Lan's user avatar
  • 63
Answer Accepted

The original data passed to ggraph gets transformed by geom_edge_link, i.e. by default get_edges() is called to extract the edges data from the graph object or the data frame in your case. As a result ...

View answer
stefan's user avatar
  • 128k
-4 votes
1 answer
73 views

Facet wrap in R for gglikert plot

i have a data frame in R with likert scale responses . Some questions are part of a broader theme. The partial data frame : df # A tibble: 264 × 3 Theme Question ...
Homer Jay Simpson's user avatar
Answer Accepted

The issue are the missings in the transformed data created by gglikert (most likely due to the wide format of the input data), i.e. even if there are no answers or responses the questions are not ...

View answer
stefan's user avatar
  • 128k
3 votes
2 answers
107 views

Concatenate values depending on variable value [closed]

I want to merge the information from 18 different databases providing information on the status of many species in different locations of the world. However, I only want to merge the rows where ...
msug's user avatar
  • 155
Answer Accepted

Assuming that df1's row 4 should really be retained in the results, here's a dplyr pipe: library(dplyr) df1 |> mutate(.by = c(taxonID, locationID), g = (establishmentMeans %in% c("introduced&...

View answer
r2evans's user avatar
  • 164k
2 votes
4 answers
114 views

More efficient way to compare if a DateTime is in between any of two columns of DateTimes in R? [duplicate]

I have a ~38,000 observation dataframe (hr_clean) that has a POSIXct value for each row, this is fitbit data that tracks average Heart Rate over every minute for the duration of a month. I want to ...
Evan N.'s user avatar
  • 31
Answer

data.table::inrange library(data.table) as.data.table(hr_clean) |> _[, is_sleeping := inrange(dateTime, sleep_ranges$startTime, sleep_ranges$endTime)] # dateTime is_sleeping # ...

View answer
r2evans's user avatar
  • 164k
3 votes
1 answer
61 views

X-axis scale over night

I have data collected over night with timestamps. I would like to plot this so that the x-axis runs from 9pm to 5am, but I can't figure out how to do it. Here is some dummy data: library(tidyverse)...
AnneA's user avatar
  • 57
Answer Accepted

Recognizing that your use of geom_bar is just a placeholder for real data and other plot needs, I think your main concern is how to adjust time and the x-axis so that it does just what you want. For ...

View answer
r2evans's user avatar
  • 164k
1 vote
1 answer
40 views

iteratively decrease values in observations for a grouped dataset without changing observations in the first rows using group_map and return a tibble

I am attempting to decrease the values of the value column by 0.000001 for observations that are not in the first row into a new column called lagged.values. I then want to fill the NAs resulting from ...
Shaq's user avatar
  • 65
Answer Accepted

Up Front: I should note that assuming perfect equality for grouping by value will be subject to floating-point issues as discussed in Why are these numbers not equal?, Is floating-point math broken?, ...

View answer
r2evans's user avatar
  • 164k
4 votes
3 answers
112 views

Only update value when pushbar closes

I have a simple app rendering the value from a switch input inside a pushbar. I'd like it so the values only update when the pushbar closes. Note for the full app, there are multiple inputs that ...
D.sen's user avatar
  • 964
Answer

We can detect the pushbar's state, save the switch value to a temporary variable, and only write it to the value that will be rendered upon closing the pushbar. I checked the class of pushbar, and it ...

View answer
M--'s user avatar
  • 30k
4 votes
1 answer
76 views

How to use a dominant fill color in geom_col_pattern when 2 colors are used?

In the following example, I want the "#1E466E" color to take about 90% of bar length. So, I tried using pattern_gravity as "right" or "left" but that does not make any ...
umair durrani's user avatar
Answer Accepted

Since R v4.1.0, you don't need to use ggpattern to create a gradient fill in ggplot2. You can do it directly by passing a grid::linearGradient as the fill colour of the bars. Furthermore, it gives a ...

View answer
Allan Cameron's user avatar
2 votes
1 answer
78 views

How to position the north arrow using tmap r package?

I want to position north arrow at the center of the scalebar. I am using the following code: library(tmap) library(terra) library(sf) r <- rast(system.file("ex/elev.tif", package="...
UseR10085's user avatar
  • 8,282
Answer Accepted

We can use tm_pos_in(..) to get closer: tm_shape(r, bbox = bbox_new) + tm_raster(col.scale = tm_scale_continuous( values = "viridis"), # color palette; col.legend = tm_legend(...

View answer
r2evans's user avatar
  • 164k


15 30 50 per page
1
2 3 4 5
127