Plot dates with regular interval in R











up vote
-1
down vote

favorite












I am trying to plot a graph in R. A snippet of the data set is shown below.



   DAY         B       C
2017-06-01 2946 197.5053
2017-06-02 5215 489.7401
2017-06-03 6305 740.6357
2017-06-04 6442 867.5795
2017-06-05 5758 1016.4603
2017-06-06 5037 1156.0188


The graph I am trying to develop is a plot of DAY (X-Axis) vs B OR C...as illustrated below.



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


The variables runs for about 3 months. I am having challenges representing the intervals on the x-Axis as I want.
What I want to do is:
format: show day and month;
intervals: every 5 days.



It has been difficult finding a solution on Base R. Most recommendations point to some complicated package and code, which is difficult to understand or apply.
Anyone with a simple solution?



Thanks.










share|improve this question
























  • ggplot2 is actually really straightforward if you take the time to work through the examples (I'm assuming that's the "complicated" package). And there are numerous examples on SO for how to use it to change axis labels.
    – hrbrmstr
    Nov 11 at 11:41










  • It actually is the complicated package I had in mind. I so far do most of my programming on base R. Maybe I would have another look at it @hrbrmstr thanks
    – SBlow
    Nov 11 at 12:20

















up vote
-1
down vote

favorite












I am trying to plot a graph in R. A snippet of the data set is shown below.



   DAY         B       C
2017-06-01 2946 197.5053
2017-06-02 5215 489.7401
2017-06-03 6305 740.6357
2017-06-04 6442 867.5795
2017-06-05 5758 1016.4603
2017-06-06 5037 1156.0188


The graph I am trying to develop is a plot of DAY (X-Axis) vs B OR C...as illustrated below.



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


The variables runs for about 3 months. I am having challenges representing the intervals on the x-Axis as I want.
What I want to do is:
format: show day and month;
intervals: every 5 days.



It has been difficult finding a solution on Base R. Most recommendations point to some complicated package and code, which is difficult to understand or apply.
Anyone with a simple solution?



Thanks.










share|improve this question
























  • ggplot2 is actually really straightforward if you take the time to work through the examples (I'm assuming that's the "complicated" package). And there are numerous examples on SO for how to use it to change axis labels.
    – hrbrmstr
    Nov 11 at 11:41










  • It actually is the complicated package I had in mind. I so far do most of my programming on base R. Maybe I would have another look at it @hrbrmstr thanks
    – SBlow
    Nov 11 at 12:20















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am trying to plot a graph in R. A snippet of the data set is shown below.



   DAY         B       C
2017-06-01 2946 197.5053
2017-06-02 5215 489.7401
2017-06-03 6305 740.6357
2017-06-04 6442 867.5795
2017-06-05 5758 1016.4603
2017-06-06 5037 1156.0188


The graph I am trying to develop is a plot of DAY (X-Axis) vs B OR C...as illustrated below.



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


The variables runs for about 3 months. I am having challenges representing the intervals on the x-Axis as I want.
What I want to do is:
format: show day and month;
intervals: every 5 days.



It has been difficult finding a solution on Base R. Most recommendations point to some complicated package and code, which is difficult to understand or apply.
Anyone with a simple solution?



Thanks.










share|improve this question















I am trying to plot a graph in R. A snippet of the data set is shown below.



   DAY         B       C
2017-06-01 2946 197.5053
2017-06-02 5215 489.7401
2017-06-03 6305 740.6357
2017-06-04 6442 867.5795
2017-06-05 5758 1016.4603
2017-06-06 5037 1156.0188


The graph I am trying to develop is a plot of DAY (X-Axis) vs B OR C...as illustrated below.



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


The variables runs for about 3 months. I am having challenges representing the intervals on the x-Axis as I want.
What I want to do is:
format: show day and month;
intervals: every 5 days.



It has been difficult finding a solution on Base R. Most recommendations point to some complicated package and code, which is difficult to understand or apply.
Anyone with a simple solution?



Thanks.







r plot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 11:26

























asked Nov 11 at 11:10









SBlow

95




95












  • ggplot2 is actually really straightforward if you take the time to work through the examples (I'm assuming that's the "complicated" package). And there are numerous examples on SO for how to use it to change axis labels.
    – hrbrmstr
    Nov 11 at 11:41










  • It actually is the complicated package I had in mind. I so far do most of my programming on base R. Maybe I would have another look at it @hrbrmstr thanks
    – SBlow
    Nov 11 at 12:20




















  • ggplot2 is actually really straightforward if you take the time to work through the examples (I'm assuming that's the "complicated" package). And there are numerous examples on SO for how to use it to change axis labels.
    – hrbrmstr
    Nov 11 at 11:41










  • It actually is the complicated package I had in mind. I so far do most of my programming on base R. Maybe I would have another look at it @hrbrmstr thanks
    – SBlow
    Nov 11 at 12:20


















ggplot2 is actually really straightforward if you take the time to work through the examples (I'm assuming that's the "complicated" package). And there are numerous examples on SO for how to use it to change axis labels.
– hrbrmstr
Nov 11 at 11:41




ggplot2 is actually really straightforward if you take the time to work through the examples (I'm assuming that's the "complicated" package). And there are numerous examples on SO for how to use it to change axis labels.
– hrbrmstr
Nov 11 at 11:41












It actually is the complicated package I had in mind. I so far do most of my programming on base R. Maybe I would have another look at it @hrbrmstr thanks
– SBlow
Nov 11 at 12:20






It actually is the complicated package I had in mind. I so far do most of my programming on base R. Maybe I would have another look at it @hrbrmstr thanks
– SBlow
Nov 11 at 12:20














1 Answer
1






active

oldest

votes

















up vote
0
down vote













library(tidyverse)

set.seed(2018-11-11)

data_frame(
DAY = seq(as.Date("2017-06-01"), as.Date("2017-08-31"), "1 day"),
B = sample(1000:6000, length(DAY)),
C = abs(rnorm(length(DAY))) * 1000
) -> sample_data

ggplot(sample_data) +
geom_point(aes(x = DAY, y = B), shape = 21) +
scale_x_date(date_breaks = "5 days", date_labels = "%bn%d") +
labs(x = "Date", y = "Revenue") +
theme_bw() +
theme(panel.grid = element_blank())


enter image description here



You claim:



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


is easier. I'll grant you it defaults to a scatterplot but now you want to do something that's going to require calling more base plot functions to customize the plot so you don't get much for free.





  • ggplot is only _two more lettersthanplot`

  • You get to specify the data frame once vs have to constantly $ reference columns


  • plot defaults to shape 21 but you'd need to use that same parameter in base plots to use different shapes so there's no difference


  • geom_point() sounds pretty straightforward to me

  • the scale_x_date() line looks pretty straightforward to me

  • theme-ing does take some reading and practice, just like anything worthwhile






share|improve this answer





















  • It actual is much easier. Thanks again. This works.
    – SBlow
    Nov 11 at 12:23











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',
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248127%2fplot-dates-with-regular-interval-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








up vote
0
down vote













library(tidyverse)

set.seed(2018-11-11)

data_frame(
DAY = seq(as.Date("2017-06-01"), as.Date("2017-08-31"), "1 day"),
B = sample(1000:6000, length(DAY)),
C = abs(rnorm(length(DAY))) * 1000
) -> sample_data

ggplot(sample_data) +
geom_point(aes(x = DAY, y = B), shape = 21) +
scale_x_date(date_breaks = "5 days", date_labels = "%bn%d") +
labs(x = "Date", y = "Revenue") +
theme_bw() +
theme(panel.grid = element_blank())


enter image description here



You claim:



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


is easier. I'll grant you it defaults to a scatterplot but now you want to do something that's going to require calling more base plot functions to customize the plot so you don't get much for free.





  • ggplot is only _two more lettersthanplot`

  • You get to specify the data frame once vs have to constantly $ reference columns


  • plot defaults to shape 21 but you'd need to use that same parameter in base plots to use different shapes so there's no difference


  • geom_point() sounds pretty straightforward to me

  • the scale_x_date() line looks pretty straightforward to me

  • theme-ing does take some reading and practice, just like anything worthwhile






share|improve this answer





















  • It actual is much easier. Thanks again. This works.
    – SBlow
    Nov 11 at 12:23















up vote
0
down vote













library(tidyverse)

set.seed(2018-11-11)

data_frame(
DAY = seq(as.Date("2017-06-01"), as.Date("2017-08-31"), "1 day"),
B = sample(1000:6000, length(DAY)),
C = abs(rnorm(length(DAY))) * 1000
) -> sample_data

ggplot(sample_data) +
geom_point(aes(x = DAY, y = B), shape = 21) +
scale_x_date(date_breaks = "5 days", date_labels = "%bn%d") +
labs(x = "Date", y = "Revenue") +
theme_bw() +
theme(panel.grid = element_blank())


enter image description here



You claim:



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


is easier. I'll grant you it defaults to a scatterplot but now you want to do something that's going to require calling more base plot functions to customize the plot so you don't get much for free.





  • ggplot is only _two more lettersthanplot`

  • You get to specify the data frame once vs have to constantly $ reference columns


  • plot defaults to shape 21 but you'd need to use that same parameter in base plots to use different shapes so there's no difference


  • geom_point() sounds pretty straightforward to me

  • the scale_x_date() line looks pretty straightforward to me

  • theme-ing does take some reading and practice, just like anything worthwhile






share|improve this answer





















  • It actual is much easier. Thanks again. This works.
    – SBlow
    Nov 11 at 12:23













up vote
0
down vote










up vote
0
down vote









library(tidyverse)

set.seed(2018-11-11)

data_frame(
DAY = seq(as.Date("2017-06-01"), as.Date("2017-08-31"), "1 day"),
B = sample(1000:6000, length(DAY)),
C = abs(rnorm(length(DAY))) * 1000
) -> sample_data

ggplot(sample_data) +
geom_point(aes(x = DAY, y = B), shape = 21) +
scale_x_date(date_breaks = "5 days", date_labels = "%bn%d") +
labs(x = "Date", y = "Revenue") +
theme_bw() +
theme(panel.grid = element_blank())


enter image description here



You claim:



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


is easier. I'll grant you it defaults to a scatterplot but now you want to do something that's going to require calling more base plot functions to customize the plot so you don't get much for free.





  • ggplot is only _two more lettersthanplot`

  • You get to specify the data frame once vs have to constantly $ reference columns


  • plot defaults to shape 21 but you'd need to use that same parameter in base plots to use different shapes so there's no difference


  • geom_point() sounds pretty straightforward to me

  • the scale_x_date() line looks pretty straightforward to me

  • theme-ing does take some reading and practice, just like anything worthwhile






share|improve this answer












library(tidyverse)

set.seed(2018-11-11)

data_frame(
DAY = seq(as.Date("2017-06-01"), as.Date("2017-08-31"), "1 day"),
B = sample(1000:6000, length(DAY)),
C = abs(rnorm(length(DAY))) * 1000
) -> sample_data

ggplot(sample_data) +
geom_point(aes(x = DAY, y = B), shape = 21) +
scale_x_date(date_breaks = "5 days", date_labels = "%bn%d") +
labs(x = "Date", y = "Revenue") +
theme_bw() +
theme(panel.grid = element_blank())


enter image description here



You claim:



plot(data$DAY, data$B, cex=0.5, xlab = "Date", ylab = "Revenue")


is easier. I'll grant you it defaults to a scatterplot but now you want to do something that's going to require calling more base plot functions to customize the plot so you don't get much for free.





  • ggplot is only _two more lettersthanplot`

  • You get to specify the data frame once vs have to constantly $ reference columns


  • plot defaults to shape 21 but you'd need to use that same parameter in base plots to use different shapes so there's no difference


  • geom_point() sounds pretty straightforward to me

  • the scale_x_date() line looks pretty straightforward to me

  • theme-ing does take some reading and practice, just like anything worthwhile







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 11:54









hrbrmstr

59.6k585146




59.6k585146












  • It actual is much easier. Thanks again. This works.
    – SBlow
    Nov 11 at 12:23


















  • It actual is much easier. Thanks again. This works.
    – SBlow
    Nov 11 at 12:23
















It actual is much easier. Thanks again. This works.
– SBlow
Nov 11 at 12:23




It actual is much easier. Thanks again. This works.
– SBlow
Nov 11 at 12:23


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248127%2fplot-dates-with-regular-interval-in-r%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues