Skip to main content
The 2024 Developer Survey results are live! See the results

R Language Collective

Questions

Browse questions with relevant R Language tags

5,412 questions

Has recommended answer
0 votes
1 answer
33 views

move inset plot legend

I have an inset plot with a legend that I want to be shown at the bottom of the overall figure. This legend isn't the same for the larger plot, since I added more layers to the inset plot. How can I ...
awray's user avatar
  • 17
Answer

One option would be to add a legend to your main plot for which I use a fake invisible geom_point and remove the legend for your inset plot. As I don't have your dataset dat.eez.usa1 I simply used the ...

View answer
stefan's user avatar
  • 115k
0 votes
1 answer
19 views

How to adjust x axis in coefficient plot with sjPlot's plot_model when x value range is smaller than -1,1?

I'm plotting multiple regression coefficients with plot_model and the x axis is automatically set to -1,1 even though the possible range of my values is smaller, which makes the estimates hard to see ...
kommoder_Waran's user avatar
Answer

As plot_model uses coord_flip under the hood you have to set the limits= for the "x" axis using scale_y_continuous: library(sjPlot) #> Learn more about sjPlot with 'browseVignettes("...

View answer
stefan's user avatar
  • 115k
2 votes
2 answers
44 views

Ploting weekly data with base::plot with unique and evenly spaced labels

I am trying to create a simple scatter plot, so weeks on the x-axis and "cases" on the y with each indicated by a dot and note I can only use base R's plot(), no ggplot. I have data with 156 ...
Fable's user avatar
  • 57
Answer Accepted

We can use seq.Date and axis.Date: plot(exampledata$Date, exampledata$Cases, main="Weeks by Cases", ylab="Cases", ylim=c(500000,900000), xlab="", ...

View answer
M--'s user avatar
  • 28.2k
1 vote
6 answers
57 views

Divide one column to three add fill up missing numbers

That's a part of my data: structure(list(Testa = c(-1L, -1L, -1L, -1L, -1L, -1L, -1L, -1L), Pre = c(NaN, NaN, NaN, ...
Shaxi Liver's user avatar
  • 1,100
Answer

This is probably better done using regex, but here is a tidyverse way: library(tidyr); library(dplyr) df |> # take the first character for Matches1 separate_wider_position( Matches, c(...

View answer
Axeman's user avatar
  • 33.8k
0 votes
1 answer
29 views

How to put a ggplot into a Word doc using Officer in R?

I am attempting to use bookmarks in Word to automatically place plots into a report. I have already used "body_replace_flextable_at_bkm" to add flextables automatically, however I cannot ...
MLBPhillies26's user avatar
Answer

While the flextable package provides a convenience function to replace a bookmark with a flextable object, the officer only provides functions to replace a bookmark with text or an image. But one ...

View answer
stefan's user avatar
  • 115k
0 votes
1 answer
22 views

Adding p-value and r-value in separate lines in correlogram using ggpairs in R

I am trying to plot a correlation matrix using the ggpairs function in the GGally R package. By default it displays the correlation coefficient in digits and adds stars next to it to represent the p-...
accibio's user avatar
  • 535
Answer Accepted

One option to achieve your desired result would be to use a customized function for which I adapted the source code of ggally_cor: library(GGally) my_ggally_cor <- function(data, ...

View answer
stefan's user avatar
  • 115k
0 votes
1 answer
23 views

Make axis lines start from specific values in ggplot

I have the following scatterplot in ggplot: library(ggplot2) ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + geom_point() + theme_classic() + scale_y_continuous(limits = c(2, 5)) + ...
Coppertank's user avatar
Answer Accepted

You can achieve your desired result using the cap= argument of guide_axis (introduced with ggplot2 3.5.0) which allows to cap the axis at the first break (aka "lower") or the last break (aka ...

View answer
stefan's user avatar
  • 115k
0 votes
3 answers
52 views

ggplot: How to merge two legend boxes and give legend keys any desired order?

I am trying to make a plot with a few stacked bars and a dot (corresponding to their sum). However, I am having troubles giving the legend keys the positions I want. In particular, I have two ...
gitcanzo's user avatar
  • 129
Answer Accepted

You can achieve your desired result easily by working with one dataset which includes all categories and by converting variable to a factor. Then use a filtered dataset for each of the geoms, map ...

View answer
stefan's user avatar
  • 115k
1 vote
1 answer
21 views

scale_fill_gradient2 colors do not reach the upper limit, even though the data does [duplicate]

I am trying to illustrate values diverging from 0 in a heat map. However, values near, and beyond the maximum appear much paler than the specified high color. library(ggplot2) genotype <- c(rep(c(&...
Adam L.'s user avatar
  • 11
Answer

If you want a dark green color for the upper limit then perhaps you want scale_fill_gradientn? Even when setting the limits with scale_fill_gradient2 the colors are evenly spaced or positioned along ...

View answer
stefan's user avatar
  • 115k
0 votes
4 answers
43 views

How to use lapply on strings so that they end up grouped together?

The actual issue: I'm trying to rearrange a bunch of names, street addresses, states, etc. into a nice list of addresses without any weird bracketed [row numbers], quotation marks, awkward breaks, etc....
silima's user avatar
  • 1
Answer

You don't really need an lapply here. You can create the vector and then write it out all in one go with write(vctrs::vec_interleave(letters, numbers), file="Text_attempt.txt") Other ...

View answer
MrFlick's user avatar
  • 204k
2 votes
5 answers
112 views

multiple times addition of two columns with dplyr

Assume I have a tibble (in my example here only with four columns). In real I have two hourly time series therefore 2 times 24 columns: s1.x,...,s24.x, s1.y,...,s24.y Now I want to sum up column s1.x ...
MPB_2022's user avatar
  • 147
Answer

I would do it with two across in this case, although pivoting might be a better option for more complex operations. library(dplyr) a |> mutate(across(matches(".x$"), .names = "{...

View answer
Maël's user avatar
  • 50.9k
0 votes
1 answer
21 views

R devtools::install(): how to install to user-local library?

I'm trying to install a package developed locally, via devtools::install(), within an R session started as normal user (not sudo) in a Linux machine. The installation fails with the error no ...
pglpm's user avatar
  • 600
Answer Accepted

If you check out the ?devtools::install help page, you'll see a note in the "Details" section that says To install a package in a non-default library, use withr::with_libpaths(). You can ...

View answer
MrFlick's user avatar
  • 204k
0 votes
1 answer
39 views

R index, filter then match on multiple criteria. Easy in excel, not so in r

I want to extract the 'untreated control' value for each variable and weed_type. In excel is easy to lookup the filter the value in the row and return the "untreated_contol" result for that ...
obs's user avatar
  • 65
Answer Accepted

Here are two possible options to achieve your desired result without the need to store the untreated value for each weed type in a separate variable: library(dplyr, warn.conflicts = FALSE) df |> ...

View answer
stefan's user avatar
  • 115k
1 vote
2 answers
32 views

Legend fails to show a category in ggplot when this category only has partial values

I have a reproducible code that generates three independent datasets and a combined dataset mydata. The dataset3 have less values, especially missing some values for certain n categories. mydata1 <-...
Phoebe's user avatar
  • 109
Answer

Personally I would simply use facetting: set.seed(123) library(ggplot2) ggplot(mydata, aes(x = n1, y = values, colour = model)) + geom_line(size = 0.6) + facet_wrap(~n, labeller = labeller(n ...

View answer
stefan's user avatar
  • 115k
0 votes
1 answer
45 views

ggplot2: Add carriage return to facet grid label without generating extra columns

I have the following code which produces the following plot: #make data frame phone <- c("p", "b", "t", "d", "k", "g", "ts", &...
Wangana's user avatar
  • 133
Answer Accepted

The issue is that you missed to add scales="free" to facet_wrap in your second code. Also note that facet_grid also allows to use a labeller=: library(ggplot2) consonant_df$p_m <- factor(...

View answer
stefan's user avatar
  • 115k
0 votes
1 answer
23 views

How to create a variable based on unique counts within a time interval by multiple time points and grouping variable?

I would like to count the unique number of drugs, defined as the number of unique drug_code dispensations each individual (noted by idnr) have within 1 year prior the index_date + time_from_index. The ...
ccalle's user avatar
  • 53
Answer Accepted

A dplyr solution: right_join( x.df, y.df |> mutate(end = index_date + time_from_index, start = `year<-`(end, year(end) - 1)), join_by(idnr, between(date_of_dispensing, start, end)) ) |> ...

View answer
Axeman's user avatar
  • 33.8k
4 votes
4 answers
46 views

How do I combine text names within an ordered transcription of dialogue?

Say I have this data: df <- data.frame(x = c("Tom: I like cheese.", "Tom: Cheese is good.", "Tom: Muenster is my favorite.&...
Tom's user avatar
  • 51
Answer

Using data.table, split on ": ", group by relid, then paste it back per group: df[, c("name", "text") := tstrsplit(x, ": ", fixed = TRUE) ][, .(text = paste(...

View answer
zx8754's user avatar
  • 55.3k
1 vote
1 answer
35 views

Pass element form character vector in loop to function and use in assign

I have a function that chooses, reads and formats Excel reports from Workday, and produces data.frames. I've simplified for purposes of begging for your help. :-) In the function, I pass a parameter ...
David Weisser's user avatar
Answer

I'd suggest to return a dataframe from the function. Then use lapply to call that function, the outputs from the lapply will be then assigned to a list object that would hold all the dataframes. ...

View answer
zx8754's user avatar
  • 55.3k
1 vote
1 answer
43 views

How to change legend key shape for ggtree [closed]

I am working with a ggtree plot. Data used is available here and you can pull the phylo tree directly from ggtree. Load required packages #load libraries pacman::p_load( here, ...
Blundering Ecologist's user avatar
Answer Accepted

If you have an up-to-date version of ggplot, you can use the key_glyph parameter to change the glyph. Using some example data from ggtree (sorry, I'm not going to download all that): library(ggtree) ...

View answer
Axeman's user avatar
  • 33.8k
0 votes
2 answers
30 views

Adding outliers to a boxplot from precomputed summary statistics

I am working with a large (50 x 800 000) sparse matrix (dgCMatrix) and want to plot a boxplot for the initial inspection of the data. This is a matrix of numeric items, with named rows (genes) and ...
stellaria's user avatar
Answer Accepted

Note that layers inherit aesthetics by default. If an aesthetic is not shared, don't specify it in the main ggplot() call. Also, avoid using "$" in aes() calls. Use data= with different data ...

View answer
MrFlick's user avatar
  • 204k
1 vote
1 answer
39 views

R get local variable from formula

Consider the R code : foo <- function(formula){ Y <- get(formula[[2]]) print(Y) } main <- function(){ Y <- 1 X <- 2 foo(Y ~ X) } main() The outcome says that in get(...
温泽海's user avatar
  • 344
Answer Accepted

By default get will look for Y in the the current environment of the call to get, which is just what is available in foo itself (i.e. pos = -1). One of the nice things about R formulas is that they ...

View answer
Axeman's user avatar
  • 33.8k
0 votes
1 answer
40 views

R How to reframe data to connect start and stop times

I have a data set that describes narwhal behaviours. There are eight whales (whaleID), multiple behaviours (behaviour), each whale can interact with none, some or all of the other whales (modID), and ...
Ghazam's user avatar
  • 27
Answer Accepted

Since each has multiple sessions, we can create an indicator that increments each time a new "start" event happens. Try df %>% arrange(time_s) %>% group_by(whaleID, behaviour, ...

View answer
MrFlick's user avatar
  • 204k
0 votes
2 answers
37 views

Mutate/cut to bin grouped data by grouped break points

I have two data-frames, each with the same groups. The first data frame consists of the base data, the second an independent set of break points for each group. I want to use those break points to ...
Jaken's user avatar
  • 93
Answer

One option would be to use split to split your dataset (and the boundaries) by groups, then bin each split individually: library(dplyr, warn = FALSE) library(purrr) iris2 <- iris |> ...

View answer
stefan's user avatar
  • 115k
8 votes
1 answer
405 views

What does "training" the data mean in the internals of ggplot2?

I'm following along with the internals of the ggplot2 library and I'm trying to understand how non-positional aesthetics get mapped to the values that get passed to grid. The book describes this ...
Dubukay's user avatar
  • 2,021
Answer Accepted

In ggplot2 terms, 'training' means keeping track of possible values. For continuous variables, this means keeping track of the range and for discrete variables, that means keeping track of the levels. ...

View answer
teunbrand's user avatar
  • 36.9k
2 votes
1 answer
31 views

geom_histogram cluster values with same fill category together

I'm trying to create a histogram which uses one column in the data set for the fill colour and another column in the data set for the groups. Both of these are define within the aes(). Then I add a ...
Amy M's user avatar
  • 1,053
Answer Accepted

Ordering is by factor levels. Using forcats we can e.g. do: ggplot( data, aes(onset_date, fill = category, group = fct_reorder(factor(grouping), category)) ) + geom_histogram( breaks = ...

View answer
Axeman's user avatar
  • 33.8k
4 votes
7 answers
142 views

Find index of two identical values in succession for the first time

These are some exemple vectors to reproduce: a <- c(14,26,38,64,96,127,152,152,152,152,152,152) b <- c(4,7,9,13,13,13,13,13,13,13,13,13,13,13) c <- c(62,297,297,297,297,297,297,297,297,297,...
climsaver's user avatar
  • 533
Answer

As clarified by OP, if the data is always increasing and starts duplicating on the last value, we just need to check unique length: lengths(lapply(list(a, b, c), unique)) # [1] 7 4 2

View answer
zx8754's user avatar
  • 55.3k
1 vote
1 answer
27 views

ggplot access inherited data object in scale_y_continuous [duplicate]

I'm trying to access the data passed to a ggplot command in a scale_y_continuous 'layer' diamonds %>% filter(cut %in% c("Very Good"), carat > 2.8) %>% ggplot(aes(x=table, y=...
pluke's user avatar
  • 4,192
Answer

This doesn't directly answer your question, but to access the data, I'd make a plotdata dataframe then call that dataframe for setting limits: plotdata <- diamonds %>% filter(cut %in% c("...

View answer
zx8754's user avatar
  • 55.3k
1 vote
1 answer
27 views

Customization of plots created with the ale package

I started using the ale package that automatically generates ggplot objects from models. I would like to remove the labels "75%", "median" and "25%" that are ...
Florence Leduc's user avatar
Answer Accepted

The labels for the horizontal lines are added via a secondary axis. Hence, one option would to get rid of these labels would be to overwrite the y scale. As you want to apply your modifications to all ...

View answer
stefan's user avatar
  • 115k
2 votes
3 answers
73 views

Complete and fill missing rows with groups of uneven length

I have a dataframe of county executives and the year they were inaugurated. I am running a panel study with county-year as the unit of analysis. The date range is 2000 to 2004. I will like to expand ...
YouLocalRUser's user avatar
Answer Accepted

We can use statar::fill_gap(): library(dplyr) df %>% group_by(district) %>% statar::fill_gap(year, full = TRUE) %>% tidyr::fill(executive.name:party, .direction = "down") %...

View answer
M--'s user avatar
  • 28.2k
1 vote
1 answer
37 views

How to get a true scatterplot matrix from GGally?

I am using ggpairs from the GGally package to make a scatterplot matrix by setting upper = list(continuous = "points"). I realized that the density plot along the diagonal actually takes ...
Arthur's user avatar
  • 1,775
Answer

I don't see an (easy) option to achieve your desired result using ggpairs. But one option would be to build your pairsplot from scratch using ggmatrix which allows for more fine-control over the ...

View answer
stefan's user avatar
  • 115k
2 votes
1 answer
45 views

What is the problem with my R code for solving and plotting a coupled system of ODE's?

I'm reasonably new to R and have this system of ODEs \frac{dS}{dT} = -\beta(1-\mu)S(t)\frac{I(t))}{1-D(t))} \frac{dI}{dT} = -\beta(1-\mu)S(t)\frac{I(t))}{1-D(t))}-\delta I(t))-\phi I(t)) \frac{dR}{dT}=...
Tom FitzGerald-Jones's user avatar
Answer Accepted

Here is a model based on the SIRD model described on wikipedia, with your mu adjustment: sird_equations <- function(time, variables, parameters) { with(as.list(c(variables, parameters)), { dS ...

View answer
Axeman's user avatar
  • 33.8k
0 votes
1 answer
59 views

How to find if an ID appears in each group? [closed]

I have a dataset that includes variables such as recordID (e.g. 1104, 4406), deposit (e.g. 100, 124), and month (e.g. 01, 02, 03, etc.). I want to find out how many of these recordIDs are making ...
user17753's user avatar
Answer

You can do this: library(dplyr) filter(dat, n_distinct(month) == 12, .by = recordID)

View answer
M--'s user avatar
  • 28.2k
1 vote
1 answer
19 views

Exporting summary.betareg and summary.gam from list to csv

I have two types of models (GAM and beta regression) that I am running for my data and I am using a lapply function to iterate over multiple variables. I am encountering an error when trying to export ...
DaniH's user avatar
  • 65
Answer Accepted

The issue is that broom does not provide a tidy method for objects of class summary.gam whereas for linear models aka models of class lm we have both a tidy.lm and a tidy.summary.lm method. While the ...

View answer
stefan's user avatar
  • 115k
1 vote
2 answers
29 views

eulerr venn diagram missing small intersection

I am trying to graph a proportional Venn diagram with eurlerr, however the final graph is missing the A&C intersection. A = 9, B = 2, C = 0, "A&B" = 28, "B&C" = 4, &...
user26384605's user avatar
Answer

Using ellipse works fine for your data, we can use residuals error plots to check, it shows which overlaps are under/over-represented, 0 meaning exact: library(gridExtra) fit1 <- euler(sizes) fit2 ...

View answer
zx8754's user avatar
  • 55.3k
1 vote
3 answers
52 views

Cell value breakdown and string split with uneven length

I need to breakdown the string values contained in a column. Some cells do not need any split at all. Others might required one, two, or more. I would also like the split values to be stored in ...
YouLocalRUser's user avatar
Answer

Using stringr, dplyr, and tidyr: df2 |> separate_wider_delim(party, delim = fixed('-'), names_sep = '', too_few = 'align_start') |> mutate(across( starts_with('party'), \(s) ...

View answer
Axeman's user avatar
  • 33.8k
1 vote
1 answer
45 views

How to manually calculate survival probabilities using flexsurvspline models [closed]

I fit a parametric survival model using flexsurvspline from flexsurv package, and would like to mannually calculate predicted survival probabilities with new data at given time points. The R code ...
Rodrigo_Wu's user avatar
Answer

The problem is that the parameters in the model are used to build splines from which the predictions are made. Trying to do this yourself from scratch would be very complex, and would be reinventing ...

View answer
Allan Cameron's user avatar
1 vote
2 answers
60 views

How to set the same width of the multiple plots in R ggplot2?

I'm trying to draw the three bar plots in one image. For the example data, I have a question about setting the width of each plot. df <- data.frame(group=c('A', 'B', 'C', 'D', 'E'), ...
Ssong's user avatar
  • 386
Answer

One easy option to achieve your desired result with less code would be to use facetting which however requires to reshape your data. Additionally to apply the limits individually per panel I use ggh4x:...

View answer
stefan's user avatar
  • 115k
0 votes
1 answer
34 views

How do I pass aesthetics to stat_summary in ggplot2?

I'm trying to produce the following plot (working example from mtcars) I can obviously do it by summarizing my data beforehand, but I would like to do it on the fly using something like this: mtcars %...
sometimes_sci's user avatar
Answer Accepted

When using stat_summary you have to use after_stat to map the computed mean value on the label aes, where in case of stat_summary the computed value is stored in a column named y. Note: I switched to ...

View answer
stefan's user avatar
  • 115k
1 vote
2 answers
74 views

How to group by one column and then a second column to summarize

I have a data frame with two ID fields similar to the following: ID 1 ID 2 Name 5 6 Apple1 5 7 Applee 6 7 Applye 3 7 Apple2 I am trying to first group by the first ID then by the second, so that ...
Jennifer Benjamin's user avatar
Answer

Here's a similar approach as the one of Edward's: read.table(text = "ID.1 ID.2 Name 5 6 Apple1 5 7 Applee 6 7 Applye ...

View answer
0 votes
1 answer
33 views

use of meta::forest() for plotting data

I would like to draw my data with meta::forest() of R but my dataset is not from a meta-anaylsis and I do not want to use ggplot2 and dplyr The data to be drawn are: study_ID, risk ratio, lb.conf.int, ...
Gábor Kovács's user avatar
Answer

By the sounds of things, your data is in this format: data #> study_ID risk ratio lb.conf.int ub.conf.int #> 1 A 2.70 1.71 4.31 #> 2 B 2.33 1....

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

Trying to create a grouped barchart in R - producing a stacked one instead

I am trying to create a bar chart that has the number of each species grouped into years. I want each year represented on the x axis with the number of each of the 3 species grouped next to one ...
Anna's user avatar
  • 51
Answer

As the variable mapped on fill is a numeric aka continuous variable you have to convert to a discrete or categorical variable using e.g. factor or explicitly map on the group aes: library(ggplot2) ...

View answer
stefan's user avatar
  • 115k
1 vote
2 answers
61 views

Display all levels in legend of ggplotly object

How do I display all legends in R ggplotly? As of now it only displays the legends for matching data. Here is what I have done so far: library(ggplot2) library(plotly) schoolname <- c("Xavier&...
Suraj Tiwari's user avatar
Answer

We can add a dummy row (schoolname == NA) with "Excellent" rating, then that level is shown in the legend without getting plotted. Moreover, you had a typo where your levels in cut() did not ...

View answer
M--'s user avatar
  • 28.2k
4 votes
5 answers
102 views

Convert a list into a tibble with nested columns

I would like to convert a list like this into a tibble. lst <- list( "A"=list( "Category"="A", "Team"=c("x"), "City"="...
mindlessgreen's user avatar
Answer

Perhaps something like: list_transpose(lst, default = NA, template = unique(unlist(map(lst, names)))) |> as_tibble() |> mutate(across(where(is.list), \(l) if (all(lengths(l) == 1)) unlist(...

View answer
Axeman's user avatar
  • 33.8k
0 votes
2 answers
29 views

Pad column numbers while using separate_wider_delim in R

I have a dataset in R that contains a column that contains a string that I want to separate into multiple columns using separate_wider_delim from the tidyr package. What I want to do is to pad the ...
BPL's user avatar
  • 127
Answer

You can specify the names, e.g. like so: df %>% separate_wider_delim( fruits_selected, delim = "+", names = sprintf("%02d", 1:3), names_sep = '_' ) If ...

View answer
Axeman's user avatar
  • 33.8k
2 votes
2 answers
70 views

How to add semicircles overlying geom_point in ggplot2

I am trying to generate a dotplot that shows changes in virus infection over time in multiple individuals. More than one virus can be detected, and I want each virus to have its own color in the ...
TurtleyAwesome's user avatar
Answer

A more elaborated option would be to use some custom shapes. The approach below builds on this answer by @AllanCameron (which I already applied here) and this answer by @Baptiste to create the custom ...

View answer
stefan's user avatar
  • 115k
0 votes
1 answer
42 views

ggsurvplot Interprets Number of Observations as Levels in newdata Argument

I am experiencing an issue with the ggsurvplot function from the survminer package in R. When attempting to plot survival curves using ggsurvplot with the newdata argument, the function incorrectly ...
Yukiyaama's user avatar
Answer

I don't have a complete answer. I think you need to provide 1 row for newdata per group, which works for the plot, but not for the table. sfit <- survfit( cox_model_single_111758446, newdata = ...

View answer
Axeman's user avatar
  • 33.8k
1 vote
3 answers
52 views

Apply command for complex functions and calculations on a dataset in R

I'm a reasonably experienced R user who has often struggled to use the apply family. I have very slow-moving iterative code whose performance I'm hoping to improve through the use of this family, but ...
St4096's user avatar
  • 87
Answer

Using the tidyverse I would write it something like: cals <- function(column, df){ var <- df |> group_by(.data[[column]]) |> summarise(ans = sum(val_1) ^ 2 + sum(val_2) ^ 2) |>...

View answer
Axeman's user avatar
  • 33.8k
0 votes
1 answer
30 views

Sorting calendar plot with geom_segment() + fix scale

I am trying to do this calendar ggplot2. So far, it works fine, but I want to make two adjustments, and I am not finding the way: I want to arrange every segment within each year and num_months, so ...
Paula's user avatar
  • 679
Answer Accepted

To fix the order make sure that the your start date column actually contains the start date for each event. To this end I added two new columns. Afterwards arrange by the start date before setting yy. ...

View answer
stefan's user avatar
  • 115k
1 vote
1 answer
31 views

Is there a way to add a pop-up window to facet_wrap ggplot titles that shows title descriptions in Quarto?

Say I have this boxplot rendered within a Quarto document: library(tidyverse) library(ggplot2) data(iris) iris %>% pivot_longer(cols = Sepal.Length:Petal.Width, names_to = '...
ksinva's user avatar
  • 361
Answer Accepted

One option would be to use ggiraph which allows to make a ggplot2 interactive. For your use case it's sufficient to leverage facet_wrap_interactive and labeller_interactive to add a tooltip to the ...

View answer
stefan's user avatar
  • 115k
1 vote
2 answers
62 views

How to draw the outermost line using scatter plot and geom density line?

I want to draw the density line on the scatter plot using ggplot2. Referencing this code, I draw the example figure below: set.seed(1) df <- data.frame(x = rnorm(200), y = rnorm(200)) ggplot(df, ...
Ssong's user avatar
  • 386
Answer

We could use ggalt::geom_encircle(): library(ggplot2) library(ggalt) set.seed(1) df <- data.frame(x = rnorm(200), y = rnorm(200)) ggplot(df, aes(x = x, y = y)) + geom_point() + ...

View answer
M--'s user avatar
  • 28.2k


15 30 50 per page
1
2 3 4 5
109