(aka Geometric objects in r ) A geom is the geometrical object that a plot uses to represent data in r. A ggplot2 geom tells the plot how you want to display your data in R. A geom defines the layout of a ggplot2 layer. People often describe plots by the type of geom that the plot uses. For example, bar charts use bar geoms, line charts use line geoms, boxplots use boxplot geoms, and so on.
Questions tagged [geom]
224 questions
2
votes
1 answer
How to make geom_linerange dodge position according to geom_point
I am trying to create a point plot with theoretical data that I generated in R. On the x-axis, I have four categories (1,2,3,4) and on the y-axis some predictions for each x-category. This is how I created the data:
x<-c(1,2,3,4,1,2,3,4)
conf.low<-…

GiorgiaA
- 55
- 4
2
votes
1 answer
How to change the linetype of a segment more than once in R using ggplot
Following the guidance presented in a previous post, I attempted to extend the solution to a dataset where the significant "Change" in grades (of 3 or more points) may be present at different months for different students, and that a Student could…

John Sandman
- 125
- 1
- 8
2
votes
1 answer
geom_boxplot custom color for quantiles
I have a simple ggplot boxplot like in this example
library(ggplot2)
dat <- ToothGrowth
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
p <- ggplot(ToothGrowth, aes(x=dose, y=len)) +
geom_boxplot() +
facet_grid(~supp)
p
Goal:
I want the…

TMC
- 75
- 10
2
votes
2 answers
How to highlight a specific region of a line changing linetype or size using ggplot
I have the following dataframe:
test = structure(list(Student = c("Ana", "Brenda", "Max", "Ana", "Brenda",
"Max", "Ana", "Brenda", "Max"), Month = structure(c(1L, 1L, 1L,
2L, 2L, 2L, 3L, 3L, 3L), .Label = c("January", "February", "March"
), class…

John Sandman
- 125
- 1
- 8
2
votes
1 answer
R weird behavior with geom_abline()
I am using this code:
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_smooth(method = "lm", se = FALSE, color = '#376795', size = 1) +
geom_abline(intercept = 34.232237, slope = -4.539474, linetype = 'dashed')
And I get this graph:
Then I…

hachiko
- 671
- 7
- 20
2
votes
0 answers
Modify the "size" of geom_link function in R
This is the dataframe
df <- data.frame(x=c(60,69,50), y=c(0,14,75), x2=c(80,78,75), y2= c(72,10,92))
and this the code
library(ggplot2)
library(ggforce)
ggplot(df) +
geom_link(aes(x = x, y = y, xend = x2, yend = y2, alpha = 0.1, size =…

Hamza Ferchichi
- 47
- 4
2
votes
1 answer
Adding a different rectangle to each facet in ggplot
I have a dataframe that I want to present in 4 facets (by ID), and for each facet, highlight the data with a rectangle.
My data is:
dt<-data.frame(ID=c(rep(c("1","2","3","4"),2)),var=c(480,1180,170,130,500,1180,1450,750),
…

EB77
- 31
- 2
2
votes
0 answers
R Change ggplot geom_quasirandom colors
R newbie on deck,
Hi everybody !
I wrote a code to visualize a geom_quasirandom (library GGbeeswarm ) for my dataset.
What works is to visualize it, but with 3 random colors for the 3 species in the dataset.
However, i do want to customize the…

mmnewbie1000
- 21
- 1
2
votes
1 answer
How to plot a cumulative frequency line graph using ggplot2?
Forgive me if this question is self explanatory, but I am still trying to get to grips with some more of R's features.
I am currently trying to use R to replot a cumulative frequency with lines I plotted in excel.
I think a lot of my problems are…

Tom Wright
- 29
- 2
2
votes
1 answer
How to fill map boundaries with external images?
I am creating a map of Brazil with its state boundaries, which is straight forward to achieve using ggplot2 and geom_sf.
However, this time around, instead of color filling each state with data, I want to fill each state's boundaries with an…

n1mrod
- 43
- 4
2
votes
0 answers
connect points within position_dodged factor x-axis in ggplot2
I'm trying to add significance annotations to an errorbar plot with a factor x-axis and dodged groups within each level of the x-axis. It is a similar but NOT identical use case to this
My base errorbar plot…

Cole Robertson
- 599
- 1
- 7
- 18
2
votes
1 answer
Issues plotting a combined shapefile in R using ggplot, no defined error given
Libraries used:
library(sp)
library(sf)
library(ggplot2)
library(ggmap)
Created a dataframe called "coordinate.data" with longitude & latitude as column names, & weather station locations as row names.
longitude <-…

Savannah Ferretti
- 25
- 3
2
votes
0 answers
Spacing out legend keys using tmap/ggplot2 in R
I'm trying to produce a map using either the tmap or ggplot2 packages and need to follow some internal design guidelines which state that legend keys should be spaced out and rectangular in shape.
I have tried tmap but the legend keys are square…

Gakku
- 337
- 2
- 8
1
vote
2 answers
Is there a way to change the linetype of the box created by geom_label?
I'm creating a graph of air temperatures in two locations, denoted on the plot by solid lines (location 1) and dashed lines (location 2). I've added geom_label annotations to display the min and max temperatures as text, and I would really like for…

cyanocitta34
- 13
- 3
1
vote
1 answer
ggplot legend with geom_tile and geom_line
I'm trying to produce a ggplot chart with two vertical axes where the user can decide which geom to use at each side. The options are lines, points and bars. I'm having troubles to have the correct shape in the legend when adding bars at the left…

djbetancourt
- 347
- 3
- 11