Most voted "ggplot2" questions
ggplot2 is a graphic design package for R based on the principles of "Graph Grammar". It partially replaces the basic Plot of R and the Lattice package, offering a clean and powerful API. It is written and actively maintained by Hadley Wickham.
Learn more…279 questions
Sort by count of
-
10
votes2
answers5010
viewsHow to correctly position the Abels in the barplot?
I am not able to correctly position the names in a barplot of R, because they are very extensive. My data is this way: The names end up appearing this way: fator_tecnologico_labels <- c(…
-
10
votes2
answers2443
viewsHow to smooth a curve in R
The goal is to get the smoothed chart from data frame. x <- c(1e-04, 0.0014, 0.018, 0.24, 3.2, 42, 560, 7500, 1e+05) y <- c(0, 7, 10, 7, 0, -7, -10, -7, 0) df <- data.frame(x, y) The curve…
-
9
votes4
answers8280
viewsHow to put the regression line on a graph?
Suppose a linear regression model like the following: set.seed(1) x <- rnorm(100) y <- rnorm(100) + 2*x +10 modelo <- lm(y~x) If I plot y against x, how do I include the regression line in…
-
9
votes2
answers1974
viewsModify gradient colors in graphs in ggplot2
How do I modify the gradient colors of a graph in ggplot? Like, I’m not getting to put a continuous color scale between white and red, I’ve tried a variety of things but still haven’t answered me.…
-
9
votes1
answer2601
viewsEdit bar graph in R: Order of X-axis values - Caption - Bar color - Insert straight - Insert comments
1 - Contextualization I want to build a bar chart using the ggplot2, however I am having difficulties to gather the information and to make the graphic edition. I have data of the oscillation of the…
-
9
votes1
answer307
viewsHow to fill column charts with hachuras using ggplot2
I would like to present column charts using the ggplot2, but I would like them to be filled with hachuras. Because it facilitates the understanding in case of photocopy in black and white! Using the…
-
8
votes1
answer1670
viewsBar graph sorted using dplyr and ggplot2
I would like to create a bar chart after counting the number of occurrences of the categories of a data set. Suppose my dataset is this below: dados <- structure(list(categorias = structure(c(5L,…
-
7
votes1
answer4682
viewsHow to create a Plot with 2 superimposed histograms?
Suppose I have the following data from 2 distinct groups. set.seed(1) grupo1<-rnorm(400,6,2) grupo2<-rnorm(200,8,2) How I make a histogram of the two groups on the same screen, identifying…
-
7
votes3
answers3287
viewsHow to put the regression equation on a graph?
On another question saw how to put the regression line on a graph. But, how to put the regression equation in the graph? For example: Or…
-
7
votes2
answers302
viewsConnecting the points to the regression line
Suppose the following database: Income <- structure(list(X = 1:30, Education = c(10, 10.4013377926421, 10.8428093645485, 11.2441471571906, 11.6454849498328, 12.0869565217391, 12.4882943143813,…
-
7
votes1
answer647
viewsChange facet_wrap order in ggplot2
See the code below, which generates the graph that comes soon after: library(lme4) library(ggplot2) ggplot(sleepstudy, aes(x=Days, y=Reaction)) + geom_point() + geom_smooth(method = "lm", se=FALSE,…
-
7
votes1
answer235
viewsPlot 3D figures for list data
I have a list a with three matrices and one vector v with any three frequencies (positive reals), these matrices form triangles through a function I created pplot. I wish to add vector information v…
-
7
votes1
answer377
viewsSize of panels with facet_wrap
I’m making some panel charts on ggplot2. See the example below: library(ggplot2) ggplot(mpg, aes(x=displ, y=hwy)) + geom_point() + geom_smooth(method="lm", se=FALSE, colour="black") + facet_wrap(~…
-
6
votes1
answer1707
viewsHow to Label Distributions in ggplot
I have the following graph of the exponential distribution, I want to put a caption showing which parameter of my exponential. ggplot(data.frame(x=c(0,5)),aes(x))+…
-
6
votes1
answer279
views3D histogram using ggplot2
I have data of a two-dimensional distribution, for example, uniform. I wish to make a histogram with this data. I tried the package plot3D, but it wasn’t very nice. teste = matrix(runif(100), ncol =…
-
6
votes1
answer1654
viewsText position on pie chart in ggplot2
I have the following table Var1 Freq Percentual Até 50 anos 4657 2.98% De 51 a 60 anos 32009 20.47% De 61 a 70 anos 57368 36.68% De 71 a 80 anos 46075 29.46% Mais de 80 anos 16299 10.42% And I need…
-
5
votes1
answer3442
viewsHow to plot the estimated logistic regression model
Suppose I have the data below, apply a logistic regression to them and want to visualize the estimated function that returns the probability. #Simula os dados nobs<-100 beta0=-10 beta1=0.006…
-
5
votes1
answer10722
viewsHow to plot a line chart with different colors depending on the value?
Suppose the following data: set.seed(1) y<-rnorm(101) x<-seq(from=0, to=100,by=1) I want to make a Plot with a line that has different color for negative values. To make a chart of points just…
-
5
votes4
answers8289
viewsHow to put different graphics of ggplot2, separately but on the same screen?
Suppose I have these 4 charts: p1 <- ggplot(mtcars, aes(mpg, cyl)) + geom_point() p2 <- ggplot(mtcars, aes(mpg, cyl)) + geom_line() p3 <- ggplot(mtcars, aes(mpg, cyl)) +…
-
5
votes2
answers620
viewsHow to smooth a curve and define ylim for a given function using ggplot2?
I got the following graph with the curve function: f1 <- function(x){x^4 - 6*(x^2)} curve(f1, xlim = c(-3, 3), ylim= c(-10, 5), ylab = expression(x^4 - 6*(x^2))) However, I would like to use the…
-
5
votes2
answers122
viewsHow can I get maximum and minimum values after applying LOESS
My data is brought from a database and I simply apply: ggplot (data = df_postgres, aes (x = date_time, y = duracao)) + geom_point() + stat_smooth(method = "loess") And I get the following smoothing:…
-
5
votes1
answer111
viewsData presentation in ggplot2
Hi, I’m having trouble at ggplot2 on a histogram. The code: ggplot(data.combined[1:891,], aes(x = Age, fill=Survived)) + facet_wrap(~Sex + Pclass) + geom_histogram(binwidth = 10) + xlab ("Age") +…
-
5
votes1
answer50
viewsProblem using ggplot by group
This is my dataframe: structure(list(ind = structure(c(177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L, 177L,…
-
5
votes1
answer1261
viewscolor gradient R
How do I change the color of the graph gradiently with the years variable, starting from white to intense red. colourCount = length(unique(tabela.estacao$ano)) getPalette =…
-
5
votes1
answer144
viewsItalics in dashboard headings in facet_wrap()
I’m having trouble formatting species names in italics in the title of the panels with the argument facet_wrap in the ggplot2. Following example: library(ggplot2) ggplot(mpg, aes(x=displ, y=hwy)) +…
-
5
votes1
answer274
viewsAutomatically identify points of influence in a regression
Whenever we make a linear regression, we need to verify that the hypotheses assumed for the model are correct. One of the best ways to do this is through diagnostic graphics. See the example below:…
-
5
votes1
answer83
viewsChange chart fill orientation
I would like to know if there is a possibility to change the orientation of the filling of the colors of the following chart What I want is for the colors to be filled from the outside in. Does…
-
5
votes1
answer735
viewsSort of Dates ggplot2
Hello, that’s my first question in this world of R and I haven’t completely mastered it yet. I am learning this wonderful language and now I have serious problems plotting a graph using the package…
-
5
votes2
answers817
viewsOverlay graphics in R with ggplot
Hello, consider two data frames: df = the number of students who answered items A,B,C,D and E of a 6-question test ITENS <-c("A","B","C","D","E") Q.1 <-c(10,20,10,40,10) Q.2…
-
5
votes2
answers226
viewsHow to add space in "boxplot" and center the middle
I would like to make two modifications to the following chart : Leave a small space between the green(F) and orange(s boxplot) Place the point referring to the median at the center of each boxplot…
-
5
votes1
answer452
viewsbar graph ggplot 2 vectors side by side
Can anyone tell me if it is possible to make this chart with the bars side by side without using data frames or "melt"? v1=c(100,120,140) v2=c(125, 102,104) a=data.frame(year=factor(2003:2005))…
-
5
votes2
answers1147
viewsColor scale adjustment on R
Good afternoon, I created a bar chart using an indicator to fill the colors of the bars, where the nearest red is bad, and the nearest green is good. It turns out that it adjusted according to the…
-
5
votes1
answer71
viewsHow to create a heatmap for a calendar?
One of the graphs I find most interesting is called, in English, heatmap Calendar. Perhaps its most common application is in github, that displays our collaborations in the last year with the chart…
-
5
votes2
answers321
viewsHow to plot map with place names - ggplot - R
I downloaded the data and plotted a map with the demographic density of the cities of the Metropolitan Region of São Paulo. But it is difficult to identify the cities. rmsp <- readOGR("rmsp",…
-
5
votes1
answer82
viewsR - Function to generate graphs and change axes
I need to display four charts several times in a Rmarkdown report. So I decided to create a function to plot the graphs. It was like this: gera_graficos <- function(base,var1,var2){ hist1 <-…
-
5
votes2
answers333
viewsLabels for Plot box in ggplot2
I have this graph created by the function geom_boxplot. Would you like to label each boxplot correctly. What am I doing wrong? I am using the wrong factor?…
-
5
votes1
answer72
viewsInclusion x-axis name of months
I am not able to change/include in the x-axis the information of months in the nominal format. Dice: dt;AverageTemperature;Month;Year;media_tempMes; 1846-01-01;26.499;1;1846;25.5466;…
-
5
votes1
answer62
viewsThere are ways to add figures on a Plot in R
Gero this figure: when using that code: library(tidyverse) library(plotly) tres <- readRDS(…
-
5
votes2
answers70
viewsError plotting with ggplot
library(tidyverse) library(lubridate) Suppose a dataset containing the year followed by the number of books published by an author: df<-tibble( ano = c(2007, 2008, 2017, 2018), n = c(1, 2, 2, 1)…
-
5
votes1
answer110
viewsReorder levels of a categorical variable within panels according to the group to which they belong
When using the command fct_reorder(class, hwy, .fun = median) below, I asked for the variable levels class were reordered according to median variable hwy: library(tidyverse) ggplot(mpg, aes(x =…
-
4
votes2
answers292
viewsggplot data.frame
I have a data.frame (df): Mês SpreadMensal 1 jan2006 -3.04045769 2 fev2006 -3.39026284 3 mar2006 -2.52839603 4 abr2006 -1.52792341 5 mai2006 -0.08979180 6 jun2006 1.02865488 7 jul2006 0.54515613 8…
-
4
votes1
answer97
viewsGgplot of a Data.frame in separate graphs
I have that date.frame: > df ind m X1 X2 1 2015-12-21 21 0.1431529 0.1426365 2 2015-12-21 42 0.1403679 0.1443714 3 2015-12-21 63 0.1467133 0.1466899 4 2015-12-21 84 0.1513388 0.1485589 5…
-
4
votes1
answer271
viewsQuadratic Curve Estimating Minimum Square using R
I have a quadratic model that I want to run a simple multivariate regression using Minimal Ordinary Squares. This is my code: df<-data.frame(rnorm(50),rnorm(50)) x_Square<-df[,2]^2…
-
4
votes1
answer131
viewsHow to fit a Lowess curve into longitudinal data using R?
I have the following data: structure(list(X26 = c(1.69, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), X27 = c(0.94, NA, NA, NA, NA,…
-
4
votes1
answer625
viewsGraph of columns of a Data Frame using GGPLOT
I have that date.frame: A K1 B K2 C K3 D K4 E K5 1 0.89386498 0.239258200 -0.004970278 0.99477685 -0.243845617 0.80370370 0.3132989 0.637155451 -0.55467576 0.049341476 2 0.35422172 0.681622485…
-
4
votes1
answer1316
viewsJoin 3 graphs using Plot
I want to join the three graphs below using the function plot. I do the basics starting with the command par(mfrow=c(1,3)) but I can’t get them together. The problem I believe is the fact that I’m…
-
4
votes1
answer650
viewsInteraction graph in ggplot2
I’m trying to adapt some standard R graphics to the style of ggplot2. One of the graphs for which I intend to do this is the interaction graph in a linear model adjustment study. The following data…
-
4
votes2
answers1312
viewsHow to change the "Key" orientation of a Caption in ggplot?
how can I change the "key" of the caption below, so that it stays in the horizontal position, without changing the vertical lines of the chart. Also, how to leave the caption background with the…
-
4
votes1
answer256
viewsHow to play a graph that was created with the Plot command using ggplot2?
How to play the chart below using the ggplot2? I don’t know how to add the various charts into one layer single! bs<-function(t,mu,phi){…
-
4
votes2
answers206
viewsScatter charts fixing a response variable
Suppose I have an interest in the dataset iris, already present in the memory of R: head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2…