how to plot a expenditure vs year in r
I have a dataset which has about 100,000 datapoints.
I want to plot two columns.
- Y axis - Year
- X axis - Sales
Sample Data:
Sales Year
22 2016
10 2016
3.99 2017
8.99 2017
12.99 2017
8.00 2016
12.00 2017
5.00 2016
22 2017
50 2016
53 2017
Im using the following code
plot(subset_4$SALES ~ subset_4$YEAR)

But the plot doesn't look great. Is there any nicer way of doing this?
Update: plot(subset_4$SALES ~ subset_4$WEEKS)

r
|
show 5 more comments
I have a dataset which has about 100,000 datapoints.
I want to plot two columns.
- Y axis - Year
- X axis - Sales
Sample Data:
Sales Year
22 2016
10 2016
3.99 2017
8.99 2017
12.99 2017
8.00 2016
12.00 2017
5.00 2016
22 2017
50 2016
53 2017
Im using the following code
plot(subset_4$SALES ~ subset_4$YEAR)

But the plot doesn't look great. Is there any nicer way of doing this?
Update: plot(subset_4$SALES ~ subset_4$WEEKS)

r
We don't have even a sample of the data nor a picture of the output so it's kinda hard to provide any guidance.
– hrbrmstr
Nov 10 at 17:16
There are many reasons why a visualization may not look nice. What does the distribution of sales look like? If it exhibits profound variance or skewedness, consider either splitting the data by month, or normalizing it to 100%. Does the graph look like a giant messy blob? Oftentimes, this is referred to as overplotting; you can try to rectify that by reducing the density of visual elements (thorugh grouping, or tweaking the transparency, or limiting the axes limits etc). Do your inputs have classes that make sense? If your dates are characters, the time axis ticks will clutter the plot.
– 12b345b6b78
Nov 10 at 17:19
Can you run the following:table(subset_4$YEAR)(to see the distribution of unique values) andclass(subset_4$YEAR)(to see the class of this column). I'm feeling like you might only have 2 unique values in the entire column.
– 12b345b6b78
Nov 10 at 17:26
I have a weeks column, can I use that?
– user3437212
Nov 10 at 17:27
You totally can. Tryplot(subset_4$SALES ~ subset_4$WEEKS)(or whatever the name of the weeks column is), and let us know what it looks like.
– 12b345b6b78
Nov 10 at 17:29
|
show 5 more comments
I have a dataset which has about 100,000 datapoints.
I want to plot two columns.
- Y axis - Year
- X axis - Sales
Sample Data:
Sales Year
22 2016
10 2016
3.99 2017
8.99 2017
12.99 2017
8.00 2016
12.00 2017
5.00 2016
22 2017
50 2016
53 2017
Im using the following code
plot(subset_4$SALES ~ subset_4$YEAR)

But the plot doesn't look great. Is there any nicer way of doing this?
Update: plot(subset_4$SALES ~ subset_4$WEEKS)

r
I have a dataset which has about 100,000 datapoints.
I want to plot two columns.
- Y axis - Year
- X axis - Sales
Sample Data:
Sales Year
22 2016
10 2016
3.99 2017
8.99 2017
12.99 2017
8.00 2016
12.00 2017
5.00 2016
22 2017
50 2016
53 2017
Im using the following code
plot(subset_4$SALES ~ subset_4$YEAR)

But the plot doesn't look great. Is there any nicer way of doing this?
Update: plot(subset_4$SALES ~ subset_4$WEEKS)

r
r
edited Nov 10 at 17:32
asked Nov 10 at 17:14
user3437212
1221112
1221112
We don't have even a sample of the data nor a picture of the output so it's kinda hard to provide any guidance.
– hrbrmstr
Nov 10 at 17:16
There are many reasons why a visualization may not look nice. What does the distribution of sales look like? If it exhibits profound variance or skewedness, consider either splitting the data by month, or normalizing it to 100%. Does the graph look like a giant messy blob? Oftentimes, this is referred to as overplotting; you can try to rectify that by reducing the density of visual elements (thorugh grouping, or tweaking the transparency, or limiting the axes limits etc). Do your inputs have classes that make sense? If your dates are characters, the time axis ticks will clutter the plot.
– 12b345b6b78
Nov 10 at 17:19
Can you run the following:table(subset_4$YEAR)(to see the distribution of unique values) andclass(subset_4$YEAR)(to see the class of this column). I'm feeling like you might only have 2 unique values in the entire column.
– 12b345b6b78
Nov 10 at 17:26
I have a weeks column, can I use that?
– user3437212
Nov 10 at 17:27
You totally can. Tryplot(subset_4$SALES ~ subset_4$WEEKS)(or whatever the name of the weeks column is), and let us know what it looks like.
– 12b345b6b78
Nov 10 at 17:29
|
show 5 more comments
We don't have even a sample of the data nor a picture of the output so it's kinda hard to provide any guidance.
– hrbrmstr
Nov 10 at 17:16
There are many reasons why a visualization may not look nice. What does the distribution of sales look like? If it exhibits profound variance or skewedness, consider either splitting the data by month, or normalizing it to 100%. Does the graph look like a giant messy blob? Oftentimes, this is referred to as overplotting; you can try to rectify that by reducing the density of visual elements (thorugh grouping, or tweaking the transparency, or limiting the axes limits etc). Do your inputs have classes that make sense? If your dates are characters, the time axis ticks will clutter the plot.
– 12b345b6b78
Nov 10 at 17:19
Can you run the following:table(subset_4$YEAR)(to see the distribution of unique values) andclass(subset_4$YEAR)(to see the class of this column). I'm feeling like you might only have 2 unique values in the entire column.
– 12b345b6b78
Nov 10 at 17:26
I have a weeks column, can I use that?
– user3437212
Nov 10 at 17:27
You totally can. Tryplot(subset_4$SALES ~ subset_4$WEEKS)(or whatever the name of the weeks column is), and let us know what it looks like.
– 12b345b6b78
Nov 10 at 17:29
We don't have even a sample of the data nor a picture of the output so it's kinda hard to provide any guidance.
– hrbrmstr
Nov 10 at 17:16
We don't have even a sample of the data nor a picture of the output so it's kinda hard to provide any guidance.
– hrbrmstr
Nov 10 at 17:16
There are many reasons why a visualization may not look nice. What does the distribution of sales look like? If it exhibits profound variance or skewedness, consider either splitting the data by month, or normalizing it to 100%. Does the graph look like a giant messy blob? Oftentimes, this is referred to as overplotting; you can try to rectify that by reducing the density of visual elements (thorugh grouping, or tweaking the transparency, or limiting the axes limits etc). Do your inputs have classes that make sense? If your dates are characters, the time axis ticks will clutter the plot.
– 12b345b6b78
Nov 10 at 17:19
There are many reasons why a visualization may not look nice. What does the distribution of sales look like? If it exhibits profound variance or skewedness, consider either splitting the data by month, or normalizing it to 100%. Does the graph look like a giant messy blob? Oftentimes, this is referred to as overplotting; you can try to rectify that by reducing the density of visual elements (thorugh grouping, or tweaking the transparency, or limiting the axes limits etc). Do your inputs have classes that make sense? If your dates are characters, the time axis ticks will clutter the plot.
– 12b345b6b78
Nov 10 at 17:19
Can you run the following:
table(subset_4$YEAR) (to see the distribution of unique values) and class(subset_4$YEAR) (to see the class of this column). I'm feeling like you might only have 2 unique values in the entire column.– 12b345b6b78
Nov 10 at 17:26
Can you run the following:
table(subset_4$YEAR) (to see the distribution of unique values) and class(subset_4$YEAR) (to see the class of this column). I'm feeling like you might only have 2 unique values in the entire column.– 12b345b6b78
Nov 10 at 17:26
I have a weeks column, can I use that?
– user3437212
Nov 10 at 17:27
I have a weeks column, can I use that?
– user3437212
Nov 10 at 17:27
You totally can. Try
plot(subset_4$SALES ~ subset_4$WEEKS) (or whatever the name of the weeks column is), and let us know what it looks like.– 12b345b6b78
Nov 10 at 17:29
You totally can. Try
plot(subset_4$SALES ~ subset_4$WEEKS) (or whatever the name of the weeks column is), and let us know what it looks like.– 12b345b6b78
Nov 10 at 17:29
|
show 5 more comments
1 Answer
1
active
oldest
votes
You can try ggplot2 library
df <- data.frame(sales, year)
ggplot(df, aes(x = sales, y = year, color = year)) +
geom_point() +
xlab("Sales") +
ylab("Year")
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%2f53241433%2fhow-to-plot-a-expenditure-vs-year-in-r%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 can try ggplot2 library
df <- data.frame(sales, year)
ggplot(df, aes(x = sales, y = year, color = year)) +
geom_point() +
xlab("Sales") +
ylab("Year")
add a comment |
You can try ggplot2 library
df <- data.frame(sales, year)
ggplot(df, aes(x = sales, y = year, color = year)) +
geom_point() +
xlab("Sales") +
ylab("Year")
add a comment |
You can try ggplot2 library
df <- data.frame(sales, year)
ggplot(df, aes(x = sales, y = year, color = year)) +
geom_point() +
xlab("Sales") +
ylab("Year")
You can try ggplot2 library
df <- data.frame(sales, year)
ggplot(df, aes(x = sales, y = year, color = year)) +
geom_point() +
xlab("Sales") +
ylab("Year")
answered Nov 10 at 20:42
pooja p
1197
1197
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53241433%2fhow-to-plot-a-expenditure-vs-year-in-r%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
We don't have even a sample of the data nor a picture of the output so it's kinda hard to provide any guidance.
– hrbrmstr
Nov 10 at 17:16
There are many reasons why a visualization may not look nice. What does the distribution of sales look like? If it exhibits profound variance or skewedness, consider either splitting the data by month, or normalizing it to 100%. Does the graph look like a giant messy blob? Oftentimes, this is referred to as overplotting; you can try to rectify that by reducing the density of visual elements (thorugh grouping, or tweaking the transparency, or limiting the axes limits etc). Do your inputs have classes that make sense? If your dates are characters, the time axis ticks will clutter the plot.
– 12b345b6b78
Nov 10 at 17:19
Can you run the following:
table(subset_4$YEAR)(to see the distribution of unique values) andclass(subset_4$YEAR)(to see the class of this column). I'm feeling like you might only have 2 unique values in the entire column.– 12b345b6b78
Nov 10 at 17:26
I have a weeks column, can I use that?
– user3437212
Nov 10 at 17:27
You totally can. Try
plot(subset_4$SALES ~ subset_4$WEEKS)(or whatever the name of the weeks column is), and let us know what it looks like.– 12b345b6b78
Nov 10 at 17:29