Reproducing plot in R using ggplot (Area plot)Plot two graphs in same plot in RHow to set limits for axes in ggplot2 R plots?How to make a great R reproducible exampleMinimize drawing size of ggplot plots by ignoring zero-length variablesSave plot to image file instead of displaying it using MatplotlibPlotting confidence intervals in ggplotPlot temporal tag coverage with ggplotColoring boxplot columns in ggplot in a repeating patternPlot a Linear Regression in ggplot2Passing a function to the ggplot density plot
Asking bank to reduce APR instead of increasing credit limit
Double integral bounds of integration polar change of coordinate
'chmod' would set file permission to 000 no matter what permission I try to set
Order by does not work as I expect
Is there a way to save this session?
Where can I find the list of all tendons in the human body?
Creating Fictional Slavic Place Names
Can a non-EU citizen travel freely within the Schengen area without passport?
Can a helicopter mask itself from Radar?
Can I ask a publisher for a paper that I need for reviewing
How can I offer a test ride while selling a bike?
Is this light switch installation safe and legal?
How does increase in volume change the speed of reaction in production of NO2?
What is a simple, physical situation where complex numbers emerge naturally?
Can you use a concentration spell while using Mantle of Majesty?
How can I stop my presentation being derailed by audience questions?
Future enhancements for the finite element method
Can you dispel the Slow effect of a Stone Golem?
Are there regional foods in Westeros?
Why would Lupin kill Pettigrew?
What is the intuition behind uniform continuity?
Can a rogue effectively triple their speed by combining Dash and Ready?
When was the word "ambigu" first used with the sense of "meal with all items served at the same time"?
How was Apollo supposed to rendezvous in the case of a lunar abort?
Reproducing plot in R using ggplot (Area plot)
Plot two graphs in same plot in RHow to set limits for axes in ggplot2 R plots?How to make a great R reproducible exampleMinimize drawing size of ggplot plots by ignoring zero-length variablesSave plot to image file instead of displaying it using MatplotlibPlotting confidence intervals in ggplotPlot temporal tag coverage with ggplotColoring boxplot columns in ggplot in a repeating patternPlot a Linear Regression in ggplot2Passing a function to the ggplot density plot
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to reproduce a plot in R where I have the data but not the code.
I think using ggplot will be the best solution.
The plot should look like this:
My data:
A dataframe (d) where column 1 ("Year") gives the year (1960 - 2000) and 15 other columns ("Group 1", "Group 2"...) giving the value of the group. Thus, each row contains the year and the values for the certain group.
(e.g. (1) 1960; 455; 367; 477; 788; 456; 334; 456;...)
I already tried some experiments with geom_area, but this does not result in the intendet graph.
ggplot(d, aes(x = Year, y = d[,2]))+
geom_area(fill = "#00AFBB", color = "blue")
Here I get n (n = # of Years) very thin bars representing the value of group 1 against a certain year.
Hope you can help me out maybe with some ideas or a tutorial. Is area plot the right choice for what I want to do?
Best!
r ggplot2 plot graphics data-visualization
add a comment |
I'm trying to reproduce a plot in R where I have the data but not the code.
I think using ggplot will be the best solution.
The plot should look like this:
My data:
A dataframe (d) where column 1 ("Year") gives the year (1960 - 2000) and 15 other columns ("Group 1", "Group 2"...) giving the value of the group. Thus, each row contains the year and the values for the certain group.
(e.g. (1) 1960; 455; 367; 477; 788; 456; 334; 456;...)
I already tried some experiments with geom_area, but this does not result in the intendet graph.
ggplot(d, aes(x = Year, y = d[,2]))+
geom_area(fill = "#00AFBB", color = "blue")
Here I get n (n = # of Years) very thin bars representing the value of group 1 against a certain year.
Hope you can help me out maybe with some ideas or a tutorial. Is area plot the right choice for what I want to do?
Best!
r ggplot2 plot graphics data-visualization
add a comment |
I'm trying to reproduce a plot in R where I have the data but not the code.
I think using ggplot will be the best solution.
The plot should look like this:
My data:
A dataframe (d) where column 1 ("Year") gives the year (1960 - 2000) and 15 other columns ("Group 1", "Group 2"...) giving the value of the group. Thus, each row contains the year and the values for the certain group.
(e.g. (1) 1960; 455; 367; 477; 788; 456; 334; 456;...)
I already tried some experiments with geom_area, but this does not result in the intendet graph.
ggplot(d, aes(x = Year, y = d[,2]))+
geom_area(fill = "#00AFBB", color = "blue")
Here I get n (n = # of Years) very thin bars representing the value of group 1 against a certain year.
Hope you can help me out maybe with some ideas or a tutorial. Is area plot the right choice for what I want to do?
Best!
r ggplot2 plot graphics data-visualization
I'm trying to reproduce a plot in R where I have the data but not the code.
I think using ggplot will be the best solution.
The plot should look like this:
My data:
A dataframe (d) where column 1 ("Year") gives the year (1960 - 2000) and 15 other columns ("Group 1", "Group 2"...) giving the value of the group. Thus, each row contains the year and the values for the certain group.
(e.g. (1) 1960; 455; 367; 477; 788; 456; 334; 456;...)
I already tried some experiments with geom_area, but this does not result in the intendet graph.
ggplot(d, aes(x = Year, y = d[,2]))+
geom_area(fill = "#00AFBB", color = "blue")
Here I get n (n = # of Years) very thin bars representing the value of group 1 against a certain year.
Hope you can help me out maybe with some ideas or a tutorial. Is area plot the right choice for what I want to do?
Best!
r ggplot2 plot graphics data-visualization
r ggplot2 plot graphics data-visualization
edited Mar 24 at 11:08
kath
5,0911026
5,0911026
asked Mar 24 at 11:04
MarlMarl
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to convert the data from wide
to long
format and then it should work:
library(dplyr)
library(tidyr)
library(ggplot2)
d <- gather(d, Group, value, Group1:Group15)
ggplot(d, aes(x = Year, y = value, fill = Group))+
geom_area()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323137%2freproducing-plot-in-r-using-ggplot-area-plot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to convert the data from wide
to long
format and then it should work:
library(dplyr)
library(tidyr)
library(ggplot2)
d <- gather(d, Group, value, Group1:Group15)
ggplot(d, aes(x = Year, y = value, fill = Group))+
geom_area()
add a comment |
You need to convert the data from wide
to long
format and then it should work:
library(dplyr)
library(tidyr)
library(ggplot2)
d <- gather(d, Group, value, Group1:Group15)
ggplot(d, aes(x = Year, y = value, fill = Group))+
geom_area()
add a comment |
You need to convert the data from wide
to long
format and then it should work:
library(dplyr)
library(tidyr)
library(ggplot2)
d <- gather(d, Group, value, Group1:Group15)
ggplot(d, aes(x = Year, y = value, fill = Group))+
geom_area()
You need to convert the data from wide
to long
format and then it should work:
library(dplyr)
library(tidyr)
library(ggplot2)
d <- gather(d, Group, value, Group1:Group15)
ggplot(d, aes(x = Year, y = value, fill = Group))+
geom_area()
answered Mar 24 at 11:27
SonnySonny
2,6241516
2,6241516
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323137%2freproducing-plot-in-r-using-ggplot-area-plot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown