(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
1
vote
1 answer
Not smooth density plot using ggplot2
When I try to plot the density of some numerical data either using geom_density() or stat_density(), I get a non-smooth curve. Using adjust do not change this.
Here I've used facet_zoom(), but also coord_cartesian(xlim = c(...)) produces this…

mas2
- 75
- 11
1
vote
2 answers
How to modify size of border lines in ggplot geom?
I'm trying to modify a histogram like this:
library(tidyverse)
iris %>%
ggplot(aes(x=Sepal.Length))+
geom_histogram(bins=10,
fill="white",
color="black",
size=1)+
labs(x="Sepal Length",
…

Shawn Hemelstrand
- 2,676
- 4
- 17
- 30
1
vote
2 answers
Multiple layer map with legend
I am trying to get a map from 2 different layers.
The first one represent country borders, the second one are grid-cells over the same area.
Drawing the map itself isn't much of an issue :
ggplot() +
geom_sf(data=country, color = "black", fill =…

yacx
- 167
- 2
- 13
1
vote
1 answer
How to dynamically assign border color using geom_node_circle?
I'm trying to change the borders of nodes in ggraph using geom_node_circle. I want to set the border colors based on a mapping between the names of the nodes and the colors that I supply for the names. I know that the parameter to change the border…

user8121557
- 149
- 2
- 9
1
vote
1 answer
How to embed the number of observations into violin plots?
I want to put data on facets of violin plots and annotate these violins with the number of observations used to plot the violin.
Here is an example of what I have without observation…

Muslimbek Abduganiev
- 828
- 7
- 21
1
vote
1 answer
Create a boxplot in ggplot with two vectors that have different sizes
I am trying to create a geom_boxplot() from two vectors but without any data frames. I can do this easily with the generic boxplot.
Given the following vectors:
runtimeWithA <- sample(20:37, size = 288, replace = TRUE)
runtimeWithoutA <-…

DeveloperInTraining
- 37
- 1
- 4
1
vote
1 answer
How to plot two variables of the same abscissa in the same line?
I want to plot two variables of the same abscissa in a same line. If it is the same abscissa, the two variables will be displayed on the same abscissa. But I want to keep them separate without affecting the coherence of the abscissa.
Here is the…

Chouette
- 153
- 7
1
vote
1 answer
theme() function doesn't work with ggplot
i have run the following code yet what is inside the "theme" function doesn't work (it does not change the legend title nor the axis title). Could anyone help fix this problem ?
ggplot() +
geom_line(aes(x = df$année,
y =…

user19304348
- 43
- 6
1
vote
2 answers
geom_line use several lines on one plot
I am currently trying to do a line plot, representing the evolution over 3 years of the number of doctors in various type of operations (one line for each), and my dataframe looks like follows :
type of operation number of doctors …

user19304348
- 43
- 6
1
vote
1 answer
geom_rect: background color repeated per season
I have a dataframe like this:
df<-data.frame(Category= c("a","b","a","b"), Value = c(25,90,40,10), Date= c("2016-02-13", "2016-05-13", "2016-08-13", "2016-11-13"))
In reality it is more complex, has several years and several observed objects so…

Annika_
- 11
- 1
1
vote
1 answer
How to make geom_path smoothed in a connected scatter plot?
I would like to make a chart like this:
But geom_path() just connects the points without any transformation.
I know that it's possible to manage it with spline transformations, but I just wanted an argument like curvature = 0.1 to make it simple.

Bruno Mioto
- 382
- 1
- 10
1
vote
2 answers
Map with geom_sf in ggplot2 missing axis labels
When creating a map in ggplot2 using sf, geom_sf I am not seeing any axis labels or graticule.
library("ggplot2")
theme_set(theme_bw())
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium",…

Arthur
- 345
- 5
- 12
1
vote
1 answer
I am looking to count the number of points in a certain region of my scatter plot with ggplot2
I have a scatter plot:
ex<- ggplot(rdr, aes(x = hb, y = iv, color = pt))+ geom_point() +
ylim(-20,20) +
xlim(-20,20) +
annotate(geom = "rect", xmin = -10, xmax = 10, ymin = -10, ymax = 10,
fill = "gray100", colour = "black", alpha…

natguy8
- 41
- 6
1
vote
1 answer
Several RColorBrewer Palettes in one ggplot
I am trying to put Several RColorBrewer Palettes that goes from lower tones to darker tones in one ggplot. But so far I've been unsuccessful and I've found that I can only use one.
My data set data:
data <- wrapr::build_frame(
"ID" ,…

Simona
- 87
- 2
- 8
1
vote
1 answer
How do I change the geom_text to currency when it is labeling a bar graph?
I have a bar graph and I have labels at the top of each bar to show the amount.
How do I change this to be in currency format?
Here is an example:
df <- tribble(~county, ~amount,
"A", 200000,
"B", 1000000,
…

Annelise Dahl
- 65
- 6