Questions tagged [ggplot2]

ggplot2 is an actively maintained open-source chart-drawing package for R, written by Hadley Wickham, based upon the principles of "Grammar of Graphics". It partially replaces R's basic plot and the lattice package, while providing a clean, powerful, orthogonal and fun API.

Filter by
Sorted by
Tagged with
0 votes
0 answers
12 views

How can I arrange a bar plot using ggplot2 based on the distribution proportions of variables?

I'm looking for a way to arrange the bar plot produced with ggplot2 by descending order of "utsugds2gp_22(happy condition)" that equal to 1 (category=not happy) within each scode1_22 group (...
Alice Chen's user avatar
0 votes
1 answer
8 views

Bar Plot with dates on x-axis issue

I have a bar plot representing data of qty over several months and I used the solution suggested here to add a double x-axis: https://stackoverflow.com/a/75897246/15573456 With bigger dataset, it ...
romina's user avatar
  • 11
0 votes
1 answer
12 views

Time series line graph for categorical data in R

enter image description here enter image description here For the time series data, it is from 2015-2021. I need to plot line graph like the one I have shown. Unfortunately, I am geeting some weird ...
Priscilla Raj's user avatar
0 votes
0 answers
29 views

Making plots using loop

I created multiple vectors and plot them one-by-one. Now, I am trying to construct a loop to plot all vectors/data in one go. I am trying to make list of all those vectors and then put that list in a ...
H.K's user avatar
  • 21
0 votes
0 answers
13 views

How can I add yellow hatching to one case in a ggplot graph with multiple types using ggplot2?

could you please help me how I can add yellow hatching to the last type ('Zemní plyn/ Vodík') in the graph? I am using this code: diff_decomp %>% ggplot(aes(x = scenario)) + geom_col(aes(y = ...
Patrik Lenz's user avatar
2 votes
1 answer
32 views

Set width of a ggplot (plotting area) to a fixed value

I have to barplots with labels (Variable item) on the y-axis that differ in their length. As the length of the labels is different the plotting area (the area with the light-gray background) is ...
D. Studer's user avatar
  • 1,689
0 votes
2 answers
19 views

Plot line graph or geom-line based on three columns and groupby

I want to plot the percentage of people by socio-economic status by AgeGroup. Below is the example of dataframe. S.NO SocioEcnomicStatus Age AgeGroup P1 2 43 36-45 AgeGroup P2 5 27 26-35 AgeGroup ...
Usman YousafZai's user avatar
0 votes
1 answer
32 views

ggplot2 stacked column: How do I sort by date, use custom colors and change the legend?

Separately these seem easy, but I can only complete two of the requirements before breaking the third. What I want to do with a stacked column chart: Group by week and order the stacked bar chart ...
seansteele's user avatar
0 votes
0 answers
24 views

Colour of boxplot based on order in graph

I have made a boxplot of some of my data, where the x-axis contains behavioural categories, and the y-axis contains a value (ODBA). I have reordered the behavioural categories to be plotted from ...
Michelle Smit's user avatar
1 vote
2 answers
29 views

Specifying different ggplot titles when using for loop to make multiple plots

I am using a loop to easily plot my data for different groups. I need a different plot for each cruise # (each year + season). I am having issues specifying a title that includes the Season and Year ...
FishyFishies's user avatar
0 votes
3 answers
29 views

How can I sort x axis values (month-year) on ggplot2 bar plot correctly?

I have a data frame which contains the following columns: J (year), M (month), Monat (which is composed as M-J), and two other variables which contain name and a month sum. The column Monat (M-J) ...
Joysn's user avatar
  • 955
0 votes
1 answer
18 views

How to join points using lines and spacing text ticks in the x axis in ggplot?

I have the following data on jeans and I want it to plot it in the most understandable way focusing on the sizes available. jeans <- tribble(~ category, ~ brand, ~size_value, "Jeans",&...
Paula's user avatar
  • 483
-3 votes
0 answers
24 views

Hello, I hope you can help me with a code in r similar to this image made by "milo" [duplicate]

By milo I am making a boxplot, including outliers. Most are on the scale of 0 to 100 on the y axis, yet I have outliers that can go as high as 3500. So in order not to rule out outliers, I hope I can ...
uhlaladeas's user avatar
0 votes
0 answers
30 views

How can I make my RStudio movie budget diagram more readable?

I need help to make a diagram more readable in RStudio. I downloaded a movie dataset from Kaggle (IMDB Top 250 Movies) and I wanted to make a diagram where the x axis is the "Genre" and the ...
Adeeb Graissy's user avatar
0 votes
1 answer
37 views

center axis.title and legend position relative to main plot in ggside

I am using ggside to plot a contour plot of data and a line plot together in one graph. This works as expected, but for me there is a problem with the position of the x and y axis title as well as the ...
Excelsior's user avatar
  • 113
0 votes
0 answers
32 views

Error "geom_line(): Each group consists of only one observation. ℹ Do you need to adjust the group aesthetic?" (line graph - repeated measures design)

I am trying to plot a line graph for two independent variables. Here are where I downloaded the data and how I converted them to a long format: textMessages <- read.delim("http://www....
WizardOfOzi's user avatar
0 votes
1 answer
62 views

How to make a learning curve

getting error while making a learning curve on binary data library(dplyr) library(tidyr) library(dplyr) library(tidyverse) library(tidytext) library(ggplot2) #data frame structure(list(ID = c(...
Conda_suman07's user avatar
0 votes
1 answer
21 views

How to make a magnified inset of a map plot with ggmagnify and ggplot2

For one of the past week's tidytuesday challenge, the one where Tornado dataset was analyzed, I tried to practice ggmagnify package with ggplot2 to make a magnified inset map of Texas with the US map. ...
mzkrc's user avatar
  • 193
0 votes
0 answers
6 views

How to modify the breaks of the legend of a contour plot using ggplot in R

I have a dataframe of a contour and want to plot this contour as lines with colour gradient. For this purpose, I want to use ggplot. For the actual data, I need a divergent color bar to show positive ...
Excelsior's user avatar
  • 113
0 votes
1 answer
13 views

How can I add the count of a character variable (year) to a barplot figure (with a defined x and y variable) in ggplot2?

I have created this barplot for the total number of cases in a year with each "Year" character representing a single study. enter image description here histo$Year <-as.character(histo$...
Christian's user avatar
0 votes
0 answers
16 views

Place ggplot in a specific coordinate of a background image by using ggdraw and draw_plot (cowplot)

I have this ggplot figure by using the well-known database mtcars. ggmtcars <- ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point(size=2, shape=23) + geom_hline(aes(yintercept = 0), color = "...
antecessor's user avatar
  • 2,658
0 votes
0 answers
38 views

Add gt table and ggplot images to email

I'm trying to add a combination of a gt table and a number of ggplot images to an email for sending to my team. It's my understanding that to include a gt table in an email it needs to be converted to ...
TheGoat's user avatar
  • 2,515
2 votes
1 answer
62 views

Arrange items in a legend in a defined way

I have below ggplot library(ggplot2) DF = data.frame(val = c(10,20,30,40,50,60,70,80,90,100), param = rep(letters[1:5],2), x = rep(c('X', 'Y'), 5)) ggplot(data = DF) + geom_bar(aes(y = val, fill = ...
Bogaso's user avatar
  • 2,754
1 vote
0 answers
33 views

How can I show specific gene names on the legend in a ggscatter plot in R using ggplot2?

Create the specific point legend with scatter plot Hi All, I am using ggscatter to make a scatter plot. I was able to create the plot legend, but I don't know how to show specific gene names on the ...
Wsabi's user avatar
  • 11
2 votes
1 answer
29 views

Programmatically position image on ggplot using annotation_custom

I am trying to create a function (inside an R package) that adds an image to the lower right corner of a ggplot. Since this will be included in a R package, I want this function to programmatically ...
Howard Baek's user avatar
0 votes
0 answers
11 views

How can I add customized text labels to a ggplot2 plot with a date x-axis?

This may interest someone: I try to add an annotation to a plot using ggplot2 package in R pt1 + ggplot2::annotate("text", x = as.Date("2022-01-01"), y = 4, label = "p < 0....
NG. Hai Tuan's user avatar
0 votes
0 answers
24 views

Using parse_expr(), quo_name(), and enquo() to define a character object for plotting country-wise graphs in ggplot

I have a function from a source that uses a couple of inputs, including country name, and return a graph for that country. The first line of the function defines a Country_name object as something ...
rez's user avatar
  • 320
0 votes
1 answer
45 views

Cannot remove mysterious zero from beneath plots

I've got five nice plots, but I've no idea why a 0 is printing beneath each. I've (at least tried) to remove x axis titles. I have no code--well, none I'm cognizant of--asking for the zeros beneath ...
RKeithL's user avatar
  • 157
0 votes
0 answers
36 views

How can I extend the plot area of ggplot2 so that geom_text added on top of geom_col is fully shown

When I place the values of bars of a barplot with geom_text on top of the bars, the values are cutted and not fully visible. How can I increase the "height" of the plot area so that the ...
Joysn's user avatar
  • 955
0 votes
1 answer
23 views

Add lines to the legend in R and ggplot2

I'm trying to make a map in R (ggplot2 and sf) but I can't seem to add transport lines to the legend. I have 4 lines (T1, T2, T3, T4) whose size I can't change either. I also can't manage to add a ...
JC_'s user avatar
  • 21
0 votes
0 answers
12 views

How to bold/thicken state border on maps made in R while including county borders?

I am trying to map all 50 US states and their respective counties. But I specifically want to thicken/bold the US state borders while keeping the county borders thin. This is the code I have tried to ...
Melissa Chen's user avatar
0 votes
0 answers
15 views

Loop to create create map from different data subsets

I am trying to create a loop so that I can plot multiple maps showing different areas of the city separately. I import the data and shapefile as follows: data = read.csv('NAME.csv') geo = read_sf(&...
enat_b's user avatar
  • 13
0 votes
0 answers
28 views

RMarkdown: Euro symbol not shown on ggplot geom_text and axis text when knitting to PDF

I use RStudio 2023.03.01 on Linux Mint (Debian edition bullseye/11.2) to write some reports in r-markdown. When the rendering in RStudio is done, the € symbol is shown on the gglot2 plots. But when I ...
Joysn's user avatar
  • 955
0 votes
1 answer
17 views

adjusting row height in ggplot lollipop

I need some help formatting my lollipop graph. The rows are too far apart from each other, with too much white space in each row therefore the top and bottom lines are too close to the edges of the ...
user2814482's user avatar
0 votes
0 answers
14 views

How to create a Stacked bar plot with percentage values and a line plot with percentage average in R using ggplot2?

How can we create a barplot similar to the one in the image using R and ggplot2? Any walkthrough will be greatly helpful.
MAS's user avatar
  • 41
-1 votes
0 answers
9 views

Can't install ggplot in latest version of Rstudio

*Install.packages("tidyverse") and install.packages("ggplot2") fails with non-zero exit status. I've tried using install.packages("tidyverse") and install.packages("...
student_2's user avatar
1 vote
1 answer
13 views

How can I match the colors of lines and legend entries in ggplot2?

I have a dataframe of some spectra (one x-value, several y-values) and want to plot them in one graph. For this purpose, I want to use ggplot. After some research, I found a way to do so, but I want ...
Excelsior's user avatar
  • 113
-2 votes
0 answers
39 views

How can I reduce the length of different letters and perform ANOVA and Tukey tests?

The letters are too long. How to reduce the length? And my code is attached. I tried many time but failed. Please help me with this. My dataset "dat1" has 4 variables: day , treatment , rep ...
Richard's user avatar
1 vote
0 answers
56 views

How do I remove plot legends using R's ggplot2 package and the opts() function or theme() function?

I am studying R programming by following the Discovering Statistics Using R by Andy Field. Chapter 4: Exploring Data with Graphs includes examples of plots (using data from discoveringstatistics.com: ...
WizardOfOzi's user avatar
0 votes
1 answer
25 views

Setting Standard Deviation to ggplot2 boxplot with 2 factors

after searching for a while, I've decided to ask my first question : it's pretty simple actually - I am plotting with ggplot2 and unfortunately the whiskers (in purple) are overlapping each other (...
Eldan Binyamini's user avatar
-1 votes
0 answers
26 views

how to color significant top hits in a manhattan plot differently according to trait

I have a manhattan plot with 3 different traits, which is the folllowing: Now, I wanna to color top hits according to the trait, like the following example I found in Mgonja et al.: I tried the ...
Khaleesi95's user avatar
-1 votes
0 answers
41 views

How can I add statistically significant letters to my ggplot in R using the nitrate data? [closed]

I want to add the statistically significance letter for my ggplot, nitrate. I tried many times, but failed. help me with the code
Richard's user avatar
2 votes
1 answer
31 views

Shapefile being read incorrectly while trying to plot spatial object?

I'm new to geo spatial analysis, and am having trouble reading my SHP file correctly when trying to do overlay plots with ggplot2. For example, if I use the .shp file from http://thematicmapping.org/...
zappbran's user avatar
0 votes
0 answers
30 views

Why does my log model trendline not plot onto the data points in ggplot2? [duplicate]

I am trying to plot trendlines based off different models onto a plot so I can then plot which is the best model (based off AIC). The trendline from the logarithmic model of the data, however, does ...
SoCo's user avatar
  • 19
0 votes
0 answers
25 views

How to plot beyond infinity with scaled axes in ggplot?

I am plotting data using a custom axis transform that compresses the values from -Infinity to Infinity to fit within a finite range. I would like to plot in positions that are beyond where Infinity ...
juhraffe's user avatar
  • 535
0 votes
1 answer
28 views

R+ggplot2+facet_wrap: preserve the with of the bars

Please have a look at the reprex at the end of the post. It is a faceted barchart where the bars are placed in decreasing order in each subplot. My only question is how to ensure that the bars have ...
larry77's user avatar
  • 1,259
0 votes
1 answer
30 views

How to align different months of the same year in a row and the same month from different years in a column in R?

I have adapted this code to create the following heatmap. I would like to rearrange the figure so that the data from different months of the same year aligns in a row, and the same month from ...
Ahsk's user avatar
  • 103
0 votes
0 answers
15 views

How to make density plot grid with groups based a column of list data in R?

I have a data frame called df_norm, which is with different parameters, and the last column 'val' is a list of data. I aim to build a density plot grid for 'val' column with pairwise of delta_mu and ...
Timon's user avatar
  • 185
0 votes
0 answers
22 views

ggplot theme text sizes not working in RShiny - works on first deploy then goes small

I'm having a weird bug with some RShiny work I'm doing. I have set ggplot themes that should apply each time a ggplot is rendered. When I first deploy the app to the internet, the sizes come out ...
Jamie's user avatar
  • 391
0 votes
0 answers
49 views

Latitude axis labels lost when mapping in ggplot2

I am working on making a map of North America. When I plot the map, the longitude axis labels show up as they are supposed to but for some unknown reason, the latitude axis labels do not show. How can ...
tassones's user avatar
  • 793

1
2 3 4 5
1070