Newest 'ggplot2' Questions - Stack Overflow

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.

-1
votes
0answers
28 views

How can I add a reverse histogram in a calibration plot with ggplot2?

I am trying to build a calibration plot and I wanted to change the geom_rug with a reversed geom_histrogram at the top. I managed to add the histogram to the graph, but both with scale_y_reverse and ...
0
votes
0answers
30 views

Why some part of my pie chart is missing in ggplot? [duplicate]

My data is > dput(df2_m) structure(list(FY = c("2018-19", "2019-20", "2018-19", "2019-20", "2018-19", "2019-20", "2018-19", "2019-20"), Finance_Type = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L),...
-2
votes
0answers
37 views

Im doing a datacamp on R visualization

Im doing a datacamp on visualizations using R and when I submit there is this message : You didn't define enough ggplot commands. Create the object containing the data and aes layers: dia_plot ...
-1
votes
1answer
21 views

How to show multiple charts in single window

I have 4 different charts but unable to show all charts in single window. tried using layout function, i guess going wrong somewhere #VPC = ggplot(VP,aes(VP$Final.Source,fill = VP$City)) + geom_bar()...
0
votes
0answers
44 views

How to re order datas in ggplot2

I'm trying to re order my datas, I already found the code to use but it doesn't seem to work... Can you help me please ? This is my code : #code for my boxplot dat.m2 <- melt(H1,id.vars='...
0
votes
0answers
28 views

How can I change group legend order with ggplot [duplicate]

I plotted a line graph. This graph has 3 groups. I want to change the order of the Legend group. This is my script dummy_plot = ggplot(data = dataplot , aes(x = factor(indexsampling),group = method)) ...
-1
votes
0answers
26 views

R: how to combine plots created in for loop [duplicate]

So, I created a for loop wich filters by the variable MULTYEAR from 2013 to 2017. For every I created a different chart. Now I want to use grid.arrange to combine each chart from the for loop. Does ...
1
vote
1answer
35 views

How to insert the difference between two bars ggplot2

I did this code: ggplot(data = df, aes(x = sex,y = weight, fill=sex))+ geom_bar(position="dodge", stat="summary",width = 0.3) +theme_classic() + scale_y_continuous(breaks = round(seq(min(0), ...
0
votes
2answers
25 views

How can I control the geometry that is included in ggplot2 legends?

I'd like to know how I can modify the geometry that appears in my legends. Here's the example I have: stockmlp %>% ggplot(aes(y = RMSE, x = Depth, color = Depth)) + geom_boxplot(alpha = 0) + ...
0
votes
1answer
20 views

How to handle kink in curve created with ggplot's stat_function?

I'm using stat_function to plot regression curves for 10 different samples in one ggplot. The plotted curve shows a kink close to the y-axis that shouldn't be there. I cannot determine the ...
1
vote
2answers
34 views

R: Producing several barcharts with ggplot2 and lapply: how to insert the subtitles according to a list?

My aim is to produce and save several bar plots with lapply and ggplot2. For this Purpose, I have created a list out of my data. Now everything works fine apart from the subtitles: I would like to ...
0
votes
0answers
43 views

Plot polygons over map [duplicate]

As of the title I want to plot over a map its regions (colored polygons) and highlight some, I think I have to use ggplot but I'm quite new in using R and I can't figure how to. I have a map obtained ...
0
votes
1answer
26 views

Is there a way to switch the position of “high” to the right and and “low” to the left on the x axis?

I just made an interaction analysis via two way ANOVA and created my graphic. Unfortunately on the x axis the condition high is alway on the left side, and the condition low is on the right side. But ...
-3
votes
0answers
20 views

error in plot points: plot.new has not been called yet [on hold]

I try to make plot with legend and text . I am working in Windows. When I tried to make graph I have no problems # I have no problems with this code library(ggplot2) Co2_data <-CO2 ggplot(data=...
1
vote
0answers
22 views

Continous Barplot on X-Axis without spaces [duplicate]

I'm trying to create a stacked barplot with the distribution of genotype at different ages. I have come quite far, but now I don't know how to solve my problem: There is a space in my x-axis between ...
1
vote
0answers
42 views

How to add linking lines for stacked 100% bar chart [duplicate]

I'd like to add linking lines for stacked 100% bar chart. As did in the following picture. Here is part of my ggplot2 code. But I don't know how to make data and use geom_line()/geom_abline()/...
1
vote
1answer
32 views

How to increase the padding around a plot?

I have a horizontal barchart, with too-tight padding: data <- data.frame(month = factor(c("Nov", "Dec", "Jan", "Feb")), count = c(1489, 788, 823, 1002)) g <- (ggplot2::...
2
votes
1answer
44 views

How to add count labels to the right of the bars in a horizontal bar chart?

For example, this code data <- data.frame(month = factor(c("Nov", "Dec", "Jan", "Feb")), count = c(1489, 788, 823, 1002)) g <- (ggplot2::ggplot(data, ggplot2::aes(x=month, y=...
0
votes
0answers
52 views

Making a waterfall chart in R using the waterfall package?

I'm trying to use the waterfall R package to create a waterfall chart, like this, per the example at this link: category <- c("Sales", "Services", "Fixed Costs", "Variable Costs", "...
0
votes
2answers
26 views

How to add areas under a geom_line?

I want to display on the same graph a geom_line and the state (which is in a vector). The data for example: Timestamp;Value;State 20190618;1.2;UP 20190619;1.0;DOWN 20190620;1.1;UP ... This is an ...
2
votes
0answers
27 views

Having trouble using override.aes for multiple geom_rect lines [on hold]

I am using a workaround rather than making an array to use geom_rect on facets of time series. You can see the different shading in the image below. The alphas are improper and are giving me varying ...
0
votes
0answers
18 views

R shiny: How to connect with fifleinput and ggplot without any selectioninput?

I am doing my first shiny app by using shiny dashboard. I get stuck in how to let users to upload in shiny app and show a bar chart(ggplot) in the Shiny App. I already complete the data upload ...
0
votes
0answers
24 views

Trouble rearranging my y axis variables using ggplot

I am working on a graph that needs to be sorted by frequency. I have figured out how to move the variables on the y axis into a decreasing order but it is sorted by the x variable values rather than ...
1
vote
1answer
26 views

R: Plotting with ggplot using multiple lines

so I'm trying to Plot chart. I filtered the original dataset Datengf to get the median income of each year (MULTYEAR) and the variable Schulbildung. No chart looks like this: chart. Now I want to plot ...
1
vote
1answer
15 views

How can I divide the frequency of a factor by a fixed value in ggplot2 geom_bar?

I want to divide all the values of bars in a geom_bar by a fixed value, to display the average value/week I have a list of attendance records, each showing the date, weekday, and the name of the ...
0
votes
0answers
26 views

How to make two bar graphs per each x value?

I am making a bar graph, that is split into three groups (Dft, dt, and ft). In each group, there should be three time periods, which each have two bars (one for male and female). I've been able to ...
0
votes
0answers
20 views

Plot several distribution and color it with a gradient

I would like to make a distribution plot like in this publication : https://www.nature.com/articles/s41598-018-35738-0.pdf for this I have a table consisting of 24 col each col representing a ...
1
vote
1answer
29 views

Filling stacked/dodged bar with different colors

I'm trying to build a chart combining stacked and dodged to compare two business lines over months on two different KPIs (VOL and NV). I would have something like this: (https://imgur.com/a/IambH09) ...
3
votes
2answers
27 views

Delete ticks between breaks in ggplot

I'd like to create a line graph with irregular break intervals on the x-axis. When I define the breaks as in the code example, I get additional unlabeled breaks, which always seem to be exactly in the ...
0
votes
0answers
16 views

R - Stop ggplot to reorder variables in facets [duplicate]

this is my dataframe. library(lubridate) date_list = seq(ymd('2019-05-01'),ymd('2019-09-30'),by='day') date_list = rep (date_list[which(month(date_list) %in% c(5:9))], 18) var_list = c("Area1", "...
1
vote
1answer
39 views

Plotting two seperate barcharts in one graph using ggplot2

I want to create a simple climate graph, plotting the precipitation and temperature of two seperate geographical places in one graph. I want to use GGplot for this. My dataset is as follows: Climate....
1
vote
0answers
27 views

R - Overlaying bar plot

I have a dataframe like this (sorry for the long code) set.seed(23) date_list = seq(1:30) testframe1 = data.frame(Date = date_list) testframe1$ABC = rnorm(30) testframe2 = data.frame(Date = ...
0
votes
1answer
18 views

Heatmap with binary outcome variables on a continous x-axis - is it possible?

Made up data Years (row): 0.5, 0.5, 1.1, 2.0 A: (column 1): 1, 0, 1, 1 B: (column 2): 0, 0, 1, 1 C: (column 3): 0 ,1 ,0, 0 I have tried to make a heatmap for my data in R, where I would like to ...
1
vote
2answers
39 views

Unable to change text labels in legend box and showing up different color in legend using ggplot

My dataframe is steps.1 interval.1 steps.2 interval.2 steps.3 interval.3 1 0 0 0 0 0 0 2 0 5 0 5 0 5 3 ...
3
votes
2answers
46 views

I found a unexpected line in my scatterplot, how can I extract all the data near the line for further analysis?

My data is about filesize and the time cost dealing with the file. When I drew the point plot I got the below result: ggplot(data,aes(filesize,time))+geom_point() You can see there are 2 lines in ...
0
votes
0answers
42 views

Fine-resolution data causing blocky GGplot line

I am trying to plot some fine resolution data using GGplot. Unfortunately, the plot is very 'blocky' and I am unsure how to fix it. Attached is a photo of the current plot I've tired changing the ...
2
votes
1answer
28 views

How do I pass a string of symbols for bquote to evaluate in ggplot?

The axis labels vary for a ggplot that I create within a function. Some of the labels have super/subscripts, while others don't. Example: m.data <- data.frame(x = runif(10), y = runif(10)) x....
1
vote
2answers
29 views

Mapping coordinates to the world map and labeling them

I have a dataframe with three columns: city_name, longitude, latitude. Using ggplot I am attempting to visualize the data using longitude and latitude as coordinates, which represent the given city. I ...
0
votes
0answers
38 views

How to add a marker on a point on ggplot?

I am trying to plot the following dataframe using ggplot2 with an added column called Condition which has Yes or No values. ID Diagnosis Age_at_Diagnosis Condition 0 A-1 ...
1
vote
0answers
34 views

flip axes of ggplot to the top and right sides using theme()

I need to flip the numbers (and tick marks) of the y-axis and x-axis to the right and top respectively (instead of where they are now). And I would like them INSIDE the map, not on the outside. This ...
0
votes
0answers
16 views

Change the default behaviour of ggplot object printing method in command line

I am trying to change the way a ggplot (or any graph actually) is printed when called in an interactive session. Essentially I'd like it to not draw in a new X window but execute arbitrary code ...
1
vote
1answer
11 views

plot slightly separated in-group bars with ggplot2 geom_bar()

Is there a way to have a little separation between each group bars made with grouped bar_plot()? Like having a bigger distance between different groups and small distance inside group bars, but not ...
0
votes
0answers
20 views

Cannot plot shapefile without lat, long, group attributes

I am using ggplot to try and add a layer with water bodies to a layer with zip codes for DC. However, when I call in the shapefile and use the function fortify() there is no "group" field in the file. ...
0
votes
1answer
25 views

replicate plot() using ggplot()

Please see attached plots using the standard plot() function vs ggplot() function. I am currently playing around with theme() to try and replicate the plot() background/panels and general look etc. ...
0
votes
1answer
32 views

R: ggplot2 multiple regression lines grouped by variable

I have a dataframe (sample below) with 3 columns. My goal is to have the variable "Return" on the y-axis and "BetaRealized" on the x-axis. Based on that, I would like to have two regression lines ...
0
votes
0answers
22 views

Barplot with base point as 0.5 [duplicate]

I already asked this question before here https://www.biostars.org/p/385463/#385552, but someone suggested me to post in R forums. I have data with genes with values ranging from 0 to 1. I made a ...
0
votes
1answer
15 views

Click an action button and save ggplot as pdf

I am attempting to download/save a dynamically output ggplot as a pdf after a downloadButton is pushed. I have attempted various ways to do this from multiple sources online and have been ...
0
votes
0answers
22 views

ggplot geom_bar - how to limit Y axis - previous suggestions not working?

Can't start Y-axis on ggplot higher up as soon as I specify c(15000000,max(variable)) I just lose all the visual aes(x= ecomm_data3$Month, y = ecomm_data3$Value, fill = ecomm_data3$Year) + ...
0
votes
1answer
23 views

ggplot: stacking graphs with x-axis labels only on bottom graph

I have a dataframe like this: ID <- c("A1", "A2", "A3", "A4", "A5", "A6") group <- c("Cats", "Cats", "Cats", "Dogs", "Dogs", "Dogs") value <- c(5, 10, 20, 5, 15, 30) data <- data.frame(...
-2
votes
1answer
27 views

why the 'fill=' function doesnt work in boxplot in ggplots?

I am making boxplot by ggplot2, but I want to divide into two groups, treated' and 'control', so I use 'fill=treatment', but still one box in each time point, however, when I use 'fill=treatment' in ...