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
-
4
votes2
answers158
viewsPlay a chart in R
I made graph 1 below in R, from the code: library(truncreg) set.seed(1) x <- sort(rnorm(50)+3) y <- 3 + 1*x + rnorm(50,0,0.3) compl <- data.frame(x,y) y[y>6.5] <- 6.5 sample <-…
-
4
votes1
answer3746
viewsHow to change the font on a chart in R?
I want to use the source Times New Roman on the chart, but the R/Rstudio returns an error message saying not to find it. Obviously the source is somewhere because I use MS Word, for example. A while…
-
4
votes1
answer241
viewsDraw lines from a specific point and angle
I’m looking for a way to draw a line from a point and an angulation (azimuth) and then construct a polygon with the intersection of these lines. base <- tibble::data_frame( id = c(1, 2, 3), x =…
-
4
votes1
answer334
viewsHow to plot a plot with ggplot
I have the following date.: sample OPN1SW OPN1MW OPN1LW RHO OPN3 OPN4 OPN5 1: GTEX-11WQK-1026-SM-5EQLX 2.365 0.0000 0 4.138 86.322 40.199 12.533 2: GTEX-XQ3S-1426-SM-4BOPR 22.317 0.0000 0 30.693…
-
4
votes1
answer175
viewsHow to loop to generate graphics in R?
Consider the following Data Frame: ITENS <-c("A","B","C","D","E") Q.1 <-c(10,20,10,40,10) Q.2 <-c(5,25,0,50,10) Q.3 <-c(15,20,5,40,10) Q.4 <-c(15,30,5,30,5) Q.5 <-c(20,25,5,20,15)…
-
4
votes2
answers1017
viewsHow to insert a chart caption with two axes y in r?
As I insert the caption in this chart, like the bar would be the gross total and the line the net total? lines = 'Mes Acid Obt Jan 1450 102 Fev 1447 86 Mar 1461 87 Abr 1356 61 Mai 1398 80 Jun 1115…
-
4
votes0
answers130
viewsPowerbi Desktop and error with R (GGPLOT)
I’m really stuck and I need help. After installing R 3.5.1, I get this error message in the R views on the Power BI Desktop I was working on earlier. "Error: package or namespace load failed for…
-
4
votes1
answer146
viewshistrogram
good morning I would like to create a histogram with 26 species in the x-axis and the percentage of influence of commercial hunting in the reduction of each species (column 'depletion_rate') on the…
-
4
votes1
answer123
views'dot Plot' relative to mean with standard deviation
Good morning In the attached graph, the points refer to the value of the average selectivity of each species. On this chart, I’d like to: 1) have larger font sizes of smaller body mass <9kg…
-
4
votes1
answer155
viewsBar graph ggplot in R
I would like to know how to remove these letters a that appear in the bar chart caption in ggplot in R. I want you to have the bar values the same way it appears in the image, but when I run the…
-
4
votes1
answer342
viewsBar graph with different colors in ggplot2
I have a bar graph in the R with percentage variation, I would like the negative percentage values to be red, as in this example: But my chart is getting this way: Code I am using:…
-
4
votes1
answer145
viewsHow to make forecast charts in R?
I have a model that makes predictions and would like to plot the observed series and then the predictions, according to this graph: I tried to use the geom_smooth along with the geom_line, but…
-
4
votes1
answer49
viewsggridges: peak heights proportional to quantities
Would anyone know if it’s possible, using the ggridges, make the heights proportional to the quantities? Follow the example: The problem is that the summit height of the first element, A624, with a…
-
4
votes1
answer130
views(Language R) How to make the axis of the graphs more detailed in ggplot2?
I would like to know how to add more numbers to my y axis, so that the bottom grid has more horizontal lines. Note that in my chart, the Y-axis only shows the markings every 500 units (0, 500, 1000…
-
4
votes1
answer28
viewsCommand line correction R in ggplot2
I used the following code to generate the attached chart ggplot(dados,aes(x = Espécies, y = DNASat, size = Reads, fill=Espécies)) + scale_y_discrete(limits = positions) + geom_point(shape = 21) +…
-
4
votes2
answers83
viewsReference one color column based on another
I have a dataset with several columns, but a specific column is reference for the colors of the chart, as I can reference this column in scale_fill_manua ggplot automatically? Obs. The same color…
-
4
votes1
answer72
viewsHow to plot the factors (spp) of the metaMDS result using ggplot2, related to the collection sites in the original data frame?
Given the following data frame: dat<-data.frame( "sitio" = c("a", "a", "a",'a', "b", "b", "b", 'b', "c", "c", "c",'c'), "amostra"=c(rep(1,4),rep(2,4),rep(3,4)), "sp1"=c(1,3,3,2,4,2,1,5,3,6,1,5),…
-
4
votes1
answer96
viewsOverlay two scatter charts into one (with ggplot)
I have 2 data frames for males and another for females (the variables are the same, crc and maxilla). From each of these df generated two charts. Now I’m trying to combine them into just one chart,…
-
4
votes1
answer85
viewsScatter plot in ggplot2
Talks guys I’m wanting to create a scatter chart in R using the ggplot2, a scatter plot with gene size (lengthbp) X variants (frameshift, splice_acceptor, splice_donor, stop_gained), the figure…
-
4
votes1
answer113
viewsLine segments leaving the interior of a map of brazil using package ggrepel
I am trying to reproduce the format of the map below, however, I have been facing some problems to insert these "straights" on the map. After a search, I found the package ggrepel that brings with…
-
4
votes2
answers101
viewsInsert scale on y-axis for geom_line
I want to plot the columns analise1, analise2, analise3 in a single chart of lines but with different scales, because the width of the column analise1 is much larger than the other two columns. On…
-
3
votes1
answer248
viewsHow to insert data for graphing in ggplot
I want to make a line chart with ggplot, but this message appears: Error: Don’t know how to add geom_point to a Plot Follow the pattern I’m doing: a<-c(4.9, 4.4, 4.2, 3.9, 3.7, 3.5, 3.1, 3, 2.9,…
-
3
votes2
answers3637
viewsHow to fix the x-axis boundaries in ggplot?
I have the following data: k <- c(294131, 734127, 817963) ano <- c(1991, 2000, 2010) dados <- data.frame(k, ano) I’m doing it this way: ggplot(dados,aes(x=ano,y=k)) + geom_point() +…
-
3
votes2
answers309
viewsPlotting Graphs ggplot inside loop
I’m wanting to create a for using ggplot: Carteira<-cbind(A, B, C,D,E,F) A, B, C,D,E,F are given in the format "zoo". My code is: for(i in 1:6){ ggplot(Carteira[,i], aes(Carteira[,i])) +…
-
3
votes3
answers955
viewsHow to place multiple formats on the dots of my PCA by ggplot2
I would like to put different shapes on the plot points of a PCA generated by ggplot2 for example (masculnos= square, female= triangle...).
-
3
votes1
answer423
viewsHow to change map scale in ggplot2?
I’m making a map with ggplot and ggmap. However, the axis scales are in decimal degrees, but I need them in degrees, minutes and seconds. Thank you for your cooperation!
-
3
votes0
answers760
viewsHow to change colors of ggplot chart?
The code below generates a graph of lines whose colors are automatically set to blue and red: ggplot(aes(x = factor(year), y1 = auto_course_choice, y2 = auto_hire, group=country)) + geom_line(aes(y…
-
3
votes1
answer82
viewsGraph of Conditional Densities of a Linear Regression
I have this data frame with two columns: Y and X. data=structure(list(Y = c(NA, -1.793, -0.642, 1.189, -0.823, -1.715, 1.623, 0.964, 0.395, -3.736, -0.47, 2.366, 0.634, -0.701, -1.692, 0.155, 2.502,…
-
3
votes2
answers290
viewsCreate a bar graph in ggplot2 with juxtaposed columns
I would like to create a bar chart on ggplot2 with x1 and x2 side by side comparing month to month. I tried the following code, but was unsuccessful: Mean_2013 <-…
-
3
votes2
answers422
viewsCode for viewing Boxplot in ggplot2
in viewing the boxplot created with the script below, it does not seem to me that the graphics g2, g3 and g4 are the same that appear in the image g1, but I couldn’t find anything wrong in the code!…
-
3
votes1
answer656
viewsHow to put percentage in bar graph?
I’m not getting a percentage of the bar chart below. I wonder if anyone can help me. dado <- data.frame("Estado" =c("ALESP", "ALRS", "ALMG"), "teste" =c(9, 29,20)) library(ggplot2) ggplot(dado,…
-
3
votes1
answer175
viewsInvert factors in only 1 bar in ggplot2
Does anyone have any idea how the order of the factors in only 1 bar in ggplot2? Reordering the data no longer works :( In case I would like to reverse the first bar, so that the green was up and…
-
3
votes1
answer62
viewsHow to plot negative coordinates (South Pole) using ggmap, ggplot?
I’m trying to plot some points between South America and the Antarctic Peninsula, but from the error when I delimit the area I wish to appear on the map (xlim, ylim). I had already plotted the map…
-
3
votes1
answer117
viewsStarting point of axis X using scale_x_date()
I am making a stacked area chart and use the following code ggplot(gdados, aes(Commissioned, acum, fill = Country)) + geom_area(col=c('black')) + scale_fill_brewer(palette = "Paired")+…
-
3
votes1
answer46
viewsComposition Graph using ggplot2
How can I produce a composition chart using ggplot2 reproducing the same model as the figure below? Sample matrix: x<-c(0, 1.52, 8.12, 0, 0.29, 0, 3, 4, 1.2, 1.1) y<-c(4.8, 3.03, 6.82, 9.76,…
-
3
votes1
answer41
viewsPlot factors (spp) of metaMDS in ggplot
I want to plot the species in the clusters of the metaMDS result using ggplot. I tried so, but gives error:Error: Aesthetics must be either length 1 or the same as the data (20): label.…
-
3
votes1
answer89
viewschange the distance between the bar and the Y axis in r
How can I change the distance of the bars relative to the y axis using ggplot? using the code: k <- c("a","b","c","d","e","f") j <- c(3,5,8,1,2,6) df <- data.frame(k,j) ggplot(df,…
-
3
votes1
answer2369
viewsStacked Bar Graph - Labels and Sort - GGPLOT
I am building a graph indicating the population of the Brazilian states, organized by regions, according to the code below: State <- c("Rondônia", "Acre", "Amazonas", "Roraima", "Pará", "Amapá",…
-
3
votes2
answers692
viewsHow to reverse the order of labels on a bar graph stacked with ggplot2?
I am trying to create a chart with the following code: ggplot(data=percent.prod, aes(x=Ano, weights=Percent)) + geom_bar(aes(fill=Tec), color="Black") + geom_text(aes(x=Ano, y=Percent, group=Tec,…
-
3
votes1
answer67
viewsHow do I adjust the lengenda to Spatial Lines in ggplot?
I’m filling lines on polygons, but when I try to insert the caption the lines get bad, how do I adjust it? Without the Legend library("ggplot2") ggplot(mapa_mg) + aes(x=long, y=lat, group=group) +…
-
3
votes3
answers433
viewsgeom_text positioning labels individually
I’m making a chart similar to this one in the example, where I position the labels by group: I’m using the code: set.seed(1000) ano=factor(rep(1996:2016,2)) cod=c(rep("K1",21),rep("O1.3",21))…
-
3
votes1
answer393
viewsCaption in ggplot does not appear
I do not know what I am doing wrong, because the caption does not appear in the graph I build. Follow my code: ND<-c("D0","D1","D2","D3e4") #diferentes níveis de desfolha (D)…
-
3
votes1
answer553
viewsError trying to draw graph: "length of the larger object is not multiple of the length of the smaller object"
I have a function: my_gamma = function(x) { f = function(t){t^(x-1) * exp(-t)} integrate(f, 0, Inf) } I’m trying to draw your chart with ggplot2: plot = ggplot(data.frame(x = seq(0.01, 10)),…
-
3
votes2
answers450
viewsBar graph with ggplot2
How can I make a graph with the data below comparing the two areas? I would like to leave the Cerrado bars on the side of the Bosque bars. I tried many times, but I could only build the chart for…
-
3
votes1
answer155
viewsStandardize bar width between distinct graphs ggplot2
Hello, I would like to know how I can standardize the width of my bars from ggplot2 between distinct charts. I would like to leave the bars of all charts at the same width. For example, I have these…
-
3
votes1
answer438
viewsHow to increase Y-axis scale marks in graphics in ggplot2?
I have a chart with very long scale marks between you, I’d like to increase the amount, but I don’t know how it’s possible. I would like to increase the number of values in the Y axis, for example,…
-
3
votes1
answer72
viewsProblem with key in ggplot, using double axis y
I would like a help to solve this problem. I would like the caption to present dotted lines (linetype), dotted (shape) and colors (colour) equal to the graph, but this graph has a double axis for y,…
-
3
votes2
answers294
viewsHow to plot distinct regression models using the ggplot2 + ggpmisc or gridExtra packages?
Hello! I have some difficulty generating graphs with different regression models (quadratic, linear) (FIGURE 1), it is observed that the graphics are loose ("free" scales) when using the…
-
3
votes0
answers45
viewsProblems with split captions in ggplot2
Hello, I’d like your help on subtitles using the ggplot2. I want to extract a caption to use in another graphic that uses plot_grid, but I don’t know why, but the same code works (Figure 1) and…
-
3
votes1
answer73
viewsHow to place the values of the discrete Y scale in ascending order?
I want to create a histogram in ggplot but the y-axis values are getting out of order. I want to place them in ascending order on the axis. I tried to use the "reorder" function but it didn’t work.…