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
-
2
votes1
answer81
viewsDoubts running ggplot 2: out-of-order data, and error bar
Hello. I’m trying to use ggplot2 to make a graph on R. This graph is a bar graph that deals with various concentrations (each concentration has a bar) on the X axis, which is associated with a…
-
2
votes1
answer150
viewsGraph of cases accumulated with ggplot2
I’m trying to make a chart according to the chart below days after 100 confirmed cases, in the case of my chart, I put as days after 10 confirmed cases: I’m using this code: library(tidyverse) dados…
-
2
votes1
answer1724
viewsHow to change the color scale on a chart in R
I have a bar chart of Brazilian states. The color of the state bar is according to the region that it belongs to. The color scale was automatically set by ggplot2, I would like to exchange these…
-
2
votes2
answers81
viewsggplot appears empty: data does not appear
I want to create a `ggplot with the frequencies at which the detections of a species of fish appear. But when I run, plot the graph without the detection frequency data, the frame is empty. How to…
-
2
votes1
answer113
viewsHow to specify facet_grid columns in ggplot2?
I’m using Google’s mobility data to compile some charts, I needed to make a 5x5 chart, where in the rows would be the states and in the columns, the locations. I tried to use the facet_grid, but it…
-
2
votes1
answer241
viewsConfidence interval using ggplot2
How to include 95% confidence interval in graph columns using ggplot2? Data frame I’m using x<-c(0.005, 0.178, 0.031, 0.058, 0.032, 0.196, 0.123, 0.159, 0.474, 0.153, 0.003, 0.012, 0.097, 0.022,…
-
2
votes1
answer70
viewsHow to plot a time series graph with ggridges?
I’m trying to plot a graph of cases per state with geom_density_ridges package ggridges, to stay that way: But by plotting the graph, it’s getting that way, all with the same line: What am I doing…
-
2
votes0
answers34
viewsAlluvial Charts - Flow does not appear
I have a table like this: Organization Timeframe Code id 1 Agencia1 Fortnight 1 International Affairs 1 2 Agencia2 Fortnight 1 Environment 2 3 Agencia2 Fortnight 1 Health 4 4 Agencia2 Fortnight 1…
-
2
votes1
answer121
viewsHow to change the colors of geom_points in R
library(tidyr) library(dplyr) library(ggplot2) library(lubridate) Suppose the following df: Ano<-c(2012:2020) Janeiro<-c(112,127,121,131,150,158,137,165,164)…
-
2
votes1
answer73
viewsI would like to edit my chart by displaying a single maximum value
Hello guys I’m having trouble displaying a value on my chart, it’s a graph of the evolution of the number of deaths in my city, my X axis is composed of March dates so far, and the Y axis with the…
-
2
votes2
answers190
viewsLabel data in column charts at "Dodge" position in R
I am working with the following data frame: library(tidyverse) df<- data.frame(Ano=c(2017, 2018,2019,2020), Vagas=c(16, 14, 27, 32), Inscritos=c(70, 107,74,88), Aprovados=c(15,14,17, 12)) df Ano…
-
2
votes1
answer88
viewsGraph of trends in ggplot2
How to play the chart below using ggplot2? Data and ggplot2 code I’m trying ano<-c("2009", "2011", "2013","2014","2016","2017","2018","2019") mean.est<-c(0.975, 1.204, 1.504, 1.741,…
-
2
votes0
answers168
viewsWhat is the best R package to plot data on maps in Brazil?
From what I researched here in the OS and Google, there are at least three different packages to build maps of Brazil in R. The package "geobr"; The package "brazilmaps" A combination of packages…
-
2
votes0
answers46
views -
2
votes0
answers27
viewsHow to count the quantity in variable using boxplot, not the frequency?
I’m trying to create a boxplot of the amount of respirators per state, but when I plot the R counts the frequency of respirators not the amount per state. There I have the following information: I…
-
2
votes2
answers39
viewsGraphic editing in ggplot2
How should I proceed to replace the caption text in the chart below "Mean.est" and "Mean.Obs" to "est" and "Obs"? Reproductive example: ano<-c("2009", "2011",…
-
2
votes1
answer28
viewsOverlay the legend of the estimated lines using the stat_poly_eq function
I adjusted different models considering the response variable (massaseca) as a function of (time) for each treatment level (content) using the ggplot2 package combined with the stat_poly_eq…
-
2
votes1
answer29
viewsX-axis values in bold
How to render the characters of the x-axis of the graph below in bold? library(ggplot2) library(tidyr) TCH <- data.frame( Período =c("Jun", "Jul"), CV6654 = c(9.38, 26.14), CTC9002 = c(16.27,…
-
2
votes1
answer40
viewsVanishing symbol when saving graphic image
In the annotations inserted by the argument annotate in the chart below in one of them has the symbol " ", but when saving the image as PDF the symbol disappears and appears "..." instead. I’d like…
-
1
votes1
answer418
viewsHow to plot several graphs on an A4 sheet with defined margins?
To illustrate the question I considered the hypothetical situation below, using the libraries ggplot2 and gridExtra. library(ggplot2) library(gridExtra) df<-data.frame(x=1:10,y=1:10)…
-
1
votes1
answer469
viewsOverlay graphics with ggplot2?
I am learning to use ggplot2 and would like to make a chart and then overlay a point on it. For example: set.seed(1) a = data.frame(X1 = rnorm(3), X2 = rnorm(3)) g <- ggplot(a, aes(x = X1, y =…
-
1
votes1
answer73
viewsNesting error
I need to make a graph in the concatenated R, are 4177 iterations, I’m using ggplot2, but is giving the error below: Error: evaluation nested too deeply: infinite recursion / options(expressions=)?…
-
1
votes1
answer446
views -
1
votes2
answers534
viewsHow to plot multiple charts on several different pages using ggplot
I have the following data frame (df): Subject Period Treatment Time Concentration 1 1 1 A -1.000 0.000 2 1 1 A -0.500 0.000 3 1 1 A -0.250 0.000 4 1 1 A 0.000 0.000 5 1 1 A 0.167 1.147 6 1 1 A 0.333…
-
1
votes1
answer252
viewsHow to make the graph start on the y-axis by ggplot?
Hello, I’m trying to get the chart below to start on axis y, but I’m not getting it. The idea is to bring the first value of the x-axis, the time 6h, to the value 0 of the y-axis. Below follows the…
-
1
votes1
answer258
viewsTurning the y-axis into a percentage
Good afternoon, I have the following command which generates the following graph: CANDIDATOS_2018_LEGISLATIVO %>% group_by(DS_ESTADO_CIVIL, DS_GENERO) %>% count() %>% ggplot(., aes(x =…
-
1
votes1
answer160
viewsPython / R Check density peaks in ggplot2
I have two sets of data formed as follows: A= {id1: 0.3, id2: 0.1, id3: 0.3 ... idn: 0.2} B= {id1: 0.01, id2: 0.04, id3: 0.75 ... idn: 0.9} I used the function ggplot R to plot the densities values…
-
1
votes1
answer2251
viewsBar graph with percentages - ggplot2
v1 = c("Sim","Não","Não","Não","Não","Sim","Sim","Sim","Sim","Sim") v2 = c("branco","branco","pardo","preto","pardo","pardo","preto","branco","preto","pardo") dados = data.frame(v1,v2) I want to…
-
1
votes1
answer27
viewsHow to plot expressions within facet_grid()?
I’m having trouble plotting two distinct expressions: expression 1: "RN (MJ m"^2~"d"^-1~")" expression 2: "ET"[0]~~" (mm"^-1*" m"^2*" )" inside: ggplot()+facet_grid(labeller = label_bquote()…
-
1
votes1
answer113
viewsHistogram of Dates in GGPLOT
I am unable to perform the ggplot of the following table: Data Frequência 1 2016-06-11 3126 2 2016-03-05 218 3 2016-01-23 431 4 2016-06-04 145 5 2016-11-30 331 6 2016-15-01 275 Through the following…
-
1
votes1
answer40
viewsWhat is the difference between the bar graph and columns in R?
I would like to know the practical difference between the bar and column charts, because I see in ggplot for example that there are commands geom_bar and geom_col. What would be better or what the…
-
1
votes1
answer592
viewsLines with alternate colors for a category variable ggplot
I have a database with ration per animal per day. Just follow one part of the base to get an idea: Animal Time Consumo 5 1 2.53396 5 2 2.32906 5 3 2.94379 5 4 3.36162 6 1 2.89082 6 2 2.53898 6 3…
-
1
votes1
answer301
viewsA: Subtitles overlaid [ggplot2]
Hello, personal,I’m having a subtitle overlay problem in ggplot. The following error message appears. Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the…
-
1
votes1
answer2209
viewsPlot 2 plots on one and y axes with different scales
Hello, masters of data analysis I have a problem plotting two Graphics with different scales on the y axis, the left represents unity and the right represents Day. I tried to find some information…
-
1
votes2
answers574
viewsDoes not create the label on the ggplot2 chart
Hello, I’m here to expose a very basic problem that is occurring, I’m not able to plot along the chart the caption. I’m not going to say much, I’m just going to put my code and the chart print out…
-
1
votes1
answer1089
viewsGraph by ggplot in Rstudio v 1.1.463 does not read Subtitle and caption in Labs()
I have the problem reported in the title and, I do not understand why in Rstudio Subtitle and caption are not read. When I replay the code in Visual Studio, it correctly loads all the commands - the…
-
1
votes1
answer230
viewsHow to send outliers with ggplot + geom_boxplot?
I have the gráfico: library(tidyverse) dataset<-as_tibble(matrix(rnorm(6*1000,1500,200),ncol=6)) cluster<-kmeans(dataset,centers=3) dataset$kmeans<-as.factor(cluster[['cluster']])…
-
1
votes2
answers74
viewsProblem in generating multiple charts
I have little experience with R and am picking up a bit to generate a ggplot with 5 geom_lin. Could you help me? The database is five annual series in months. 2014 2015 2016 2017 2018 jan 10 8 7,5 5…
-
1
votes2
answers283
viewsx-axis for time series in ggplot
I have a graph with the following syntax in ggplot n <-data.frame(x = c(NEP$NEPeleitoral), y = c(NEP$`NEP parlamentar`), z = c(NEP$anoeleicao)) ggplot(n, aes(x = n$z, y = n$x)) +…
-
1
votes2
answers1868
viewsHow to position the title in ggplot2 with theme_ipsum?
I have the following data dados B Freq 1 Feminino 61.54 2 Masculino 38.46 With the code below I graph a pizza using the package ggplot2: library(ggplot2) library(hrbrthemes) dados <- data.frame(B…
-
1
votes1
answer465
viewsChange colors of the scale of a bubble chart in R
I’m having trouble creating a color scale for my chart nome<-c("a","b","c","d") anos<-c(15,8,25,9) renda<-c(14,5,3,25) final<-c(30,15,42,12) tudo<-cbind(nome,anos,renda,final)…
-
1
votes2
answers2242
viewsShow Data Labels in Column Chart in R (ggplot2)
I’m a beginner in R and I’m trying to create a bar chart and I can’t display the data labels on each bar. Follow link to the used data frame:…
-
1
votes0
answers128
viewsHow to create graph in Rstudio with ggplot?
I need to create a simple bar graph with data from a data frame. But I want to divide each bar of the graph into three. For example: In the bar referring to the year 2000, I have to put three…
-
1
votes0
answers113
viewscolors of the interaction line in a network
I would like to elaborate a network (network) type chart. In this chart I would like the colors of the interaction lines (col.interaction) are the same colour as the upper boxes (col.high). Could…
-
1
votes1
answer75
viewsHow to plot only a part of a Posixct variable?
I have a df with two variables. The first is a time counter that reaches 9min at a 1000Hz acquisition rate (so it’s huge 540 thousand lines). The second variable is an electrophysiological…
-
1
votes1
answer396
viewsR - Geom_col with division per year
Expensive, I have the following database: I want to plot a chart like the one below using ggplot: I’m trying to do this with the following code, but I’m not getting a good result. ggplot(Database,…
-
1
votes1
answer612
viewsHow to break a line in the title of the graph into 2 lines using ggplot?
I need to break the title line of the chart so that it stays at the width of the chart itself. The reason is that the chart will be used in a grid.arrange() and in this way it will become narrow and…
-
1
votes0
answers59
viewsERROR: The "x" line break is not justifying left
I made a line break in the title of the "x" axis using the " n" and the break did not respect the horizontal justification on the left. Follow the data: > dput(PCLstack) structure(list(Grupo =…
-
1
votes1
answer474
viewsBar graph in ggplot in r
The database I’m reading is as follows: Trimestre PIB 1º T 2018 0.005 2º T 2018 0.000 3º T 2018 0.005 4º T 2018 0.001 1º T 2019 -0.001 2º T 2019 0.004 I made a bar Plot with the following code:…
-
1
votes2
answers251
viewsR - brazilmaps (border of states)
I created a map of SP and MG states using brazilmaps(). On this map I filled some cities with values. However, I would like to make the border of states appear on Plot. How do I do that? Follow what…