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.
ggplot2
56,846
questions
0
votes
0
answers
9
views
How to Improve Kernel Density Estimation Plot Map Grid Cells for Vessel Traffic on the West Coast of Mexico in R?
I'm working on visualizing vessel traffic density for the west coast of Mexico, including Baja California and Bahia de Banderas waters, using R. I have a large dataset of vessel locations stored in a ...
0
votes
1
answer
22
views
ggrepel how to force geom_text_repel to draw a label line between the text label and its respective point?
> dput(d)
structure(list(line = structure(c(4L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, ...
0
votes
1
answer
19
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", &...
0
votes
0
answers
31
views
Subset a shapefile by lat/long
I have a shapefile from this site that I am working with. I'd like to only plot the a) 30 fathom layer, and b) this layer on latitudes above 34.4. I've been able to subset only the 30 fathom layer, ...
1
vote
1
answer
36
views
How to change legend key shape for ggtree
I am working with a ggtree plot. The data used is available here.
Load required packages
#load libraries
pacman::p_load(
here,
dplyr,
googlesheets4,
...
0
votes
2
answers
28
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 ...
0
votes
0
answers
46
views
How to remove hex codes that are visible during transition while using gganimate library in R?
I created an animated bar plot using ggplot and gganimate. The data labels are numbers and are comma separated using the comma function in the scales library. But while the bars are changing from one ...
0
votes
1
answer
20
views
How to set the range of colorbar manually regardless of the real range of values using ggplot2?
I want to draw the heatmap while setting the customized range of values.
Since the original data has large range of values, I set the limitation of coloring by Q1, Q3, and IQR.
In this case, the range ...
0
votes
1
answer
36
views
In below `geom_smooth` how to make line fluctuate match with original data
In below geom_smooth, the line year 2023 is smoother than year 2024, but the 2023 amount SD is 20 lager then 2024 15. How to fix it?
library(tidyverse)
df_2023 <- data.frame(mdate =seq.Date(from=...
2
votes
1
answer
37
views
How to skip ggsave when create plot failed or empty plot
In the code below, how can I skip
ggsave(paste0(single_color,"_plot.png"))
when the code
plot_data <- diamonds %>% filter(color== single_color) errors or plot_data is empty ?
library(...
1
vote
1
answer
64
views
How to use average value in geom_line?
I am struggling to make a continuous line graph with bar plot.
I used the below code to make this graph.
Is there any way I can use geom_line with average value?
ggplot(df, aes(Date, Rain)) +
...
9
votes
1
answer
368
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 ...
0
votes
0
answers
52
views
Difference in the visual output of two images generated by the same R code [closed]
I know this is probably a very dumb question, but I cannot really understand this issue that has happened to me several times. In particular I will give you this example: I tried to generate a radar ...
2
votes
1
answer
26
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 ...
0
votes
1
answer
44
views
Add data table on x axis in ggplot in R?
I'm using R to make a combined barplot + line with ggplot2. I want to add a data table in the x axis just like it's possible to do in excel.
This is my data and the plot I managed to make:
graf4 <- ...