(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
4
votes
2 answers
Geom_Hex coloring by 3rd variable
I'm trying to create a normal hexbin plot but instead of coloring the plot by count, the default, I would like to have it colored by the average value of a third variable. In my particular case, I cannot use the stat_summary_hex…

Justin
- 153
- 2
- 10
4
votes
1 answer
Fill in continuous colors in geom_sf
I am running codes to create maps in R:
library(tidyverse)
library(ggplot2)
library(eurostat)
library(janitor)
library(sf)
eugd <- eurostat_geodata_60_2016 %>% clean_names()
eugdtr <- eugd %>% st_transform(crs = 3035)
gd_de <- eugdtr %>%…

sylvia
- 197
- 1
- 8
4
votes
1 answer
Building a new geom_hurricane
I have been meaning to create a new geom for a data set that has been tidied in the following form:
Katrina
# A tibble: 3 x 9
storm_id date latitude longitude wind_speed ne se sw nw
…

Anoushiravan R
- 21,622
- 3
- 18
- 41
4
votes
1 answer
Error in st_normalize.sfc(x, c(x_range[1], y_range[1], x_range[2], y_range[2])) : domain must have a positive range
Background:
I am using ggplot2 geom_point to map animal location points by week. As a basemap, I am using a shapefile from my computer.
Here is an example of my data:
datexample <- data.frame(
"animal" = c("A","B"),
"yearweek" = c(202028,…

cgxytf
- 421
- 4
- 11
3
votes
2 answers
geom_boxplot with mapped, variable widths per bar?
I would like to be able to map the width of each of the boxplots in a plot to a variable, or otherwise specify it. Let's say I want the relative widths of the boxes in the figure below to be 1, 2, 3. Setting varwidth won't help me since the actual…

Ben Bolker
- 211,554
- 25
- 370
- 453
3
votes
2 answers
Adding the maximum (peak) value in ggplot for geom_smoth
I have a geom_smooth that has an x-axis date, y-axis COVID cases, and then two categories.
I'm trying to plot the maximum peak.
# Reproducible data
library(tidyverse)
df <- tribble(~date, ~cases, ~category,
"2021/1/1", 100, "A",
…

Annelise Dahl
- 65
- 6
3
votes
2 answers
How to plot a world map using R
I am working on a project and a small part of it is plotting a world map with the 135 countries I have in my list. I also have a list that says whether they are developed or not.
How do I put this in the world map with different colors for the…

Rhedavetester
- 65
- 6
3
votes
1 answer
How to find the geom_line control points in ggplot
I was able to find the geom_curve control points in ggplot using the answer on this question:
How to find the geom_curve control points in ggplot
I am now wondering how to apply this same function to geom_line to obtain all the control points along…

Isabelle
- 31
- 2
3
votes
1 answer
How can I get the center point of a polygon in MySQL 8?
I just called the ST_CENTROID(), MySQL 8 returns:
[22001][3618] Data truncation: st_centroid(POLYGON) has not been implemented for geographic spatial reference systems.
I want get polygons from my db which should be within a circle, I use the…

康少麒
- 31
- 2
3
votes
2 answers
Is there any way to use 2 color scales on the same ggplot?
With the data separated by categories (Samples A and B), 2 layers were made, one for points and one for lines. I want to separate my data by category indicating colors for the points and also separate the lines but with different colors than those…

Daniel Valencia C.
- 2,159
- 2
- 19
- 38
3
votes
0 answers
Pixelated (not-smooth) curve in geom_function
How can I smoothen the chart line using ggplot2
I am trying to plot a graph for this function
exposure_funct_0.25 <- function(x) {
exp(-0.25*x)
}
exposure_funct_0.5 <- function(x) {
exp(-0.5*x)
}
ggplot(data.frame(x = c(0,15)), aes(x=x)) +…

quachtoanlong
- 57
- 5
2
votes
1 answer
How to align geom_boxplot and geom_point with uneven observations per group?
I am trying to generate a grouped boxplot in ggplot2 with overlaid points for each sample in the dataset. I am trying to use position_dodge2(preserve = "single") to preserve the width of the boxplots when there are missing values in a group, however…

yasmin
- 49
- 3
2
votes
0 answers
How to I change the colour fill on stat_ellipsis(geom='polygon') to match the scale_color_brewer palette colours for PCA plot?
I am using the autoplot() function to add ellipsis and polygons to my PCA plot in R, my colour palette for the points is the color.brewer 'Set2' palette. When I am filling my ellipsis with geom='polygon', I want the polygon fill colour to be the…

JamesLG
- 21
- 1
2
votes
2 answers
ggplot2 geom_jitter jitters in y direction?
I am very puzzled. When using ggplot2, many uses geom_jitter to add points to boxplots for instance. It is supposed to keep values on the Y-axis, at least as far as I know, and jitter values on the X-axis.
Using it today on two groups, 3 points per…

PM_from_Mars
- 23
- 3
2
votes
1 answer
How do I draw a complete box around a cropped shapefile using geom_sf?
I currently have a ggplot of multiple shapefiles that are cropped to be inside a certain bounding box. I want to draw a complete box around the entire region, but the portions of the plot that crop out a shapefile polygon (Mexico's southern edge &…

Andy G
- 21
- 1