missing yearmon labels using ggplot scale_x_yearmonHow to display the December in xaxis when using autoplot and yearmonRotating and spacing axis labels in ggplot2working with months in zooPlotting monthly data with ggplotggplot2 stats=“identity” and stacking colors in bar plot gives “striped” bar chartBarplot without lexicographical order in ggplotggplot geom_text not seating on top of barsggplot: line plot for discrete x-axisConverting a factor time variable to yearmon variableHow to reorder the groups in a grouped bar-chartsort by month and year R
Why didn’t Eve recognize the little cockroach as a living organism?
How were servants to the Kaiser of Imperial Germany treated and where may I find more information on them
Isometric embedding of a genus g surface
Origin of pigs as a species
How to get directions in deep space?
Storage of electrolytic capacitors - how long?
Review your own paper in Mathematics
How to I force windows to use a specific version of SQLCMD?
What is this high flying aircraft over Pennsylvania?
What should be the ideal length of sentences in a blog post for ease of reading?
Overlapping circles covering polygon
Would a primitive species be able to learn English from reading books alone?
If Captain Marvel (MCU) were to have a child with a human male, would the child be human or Kree?
Are inadvertent environmental catastrophes also examples of natural selection?
Why is the principal energy of an electron lower for excited electrons in a higher energy state?
Why is the sun approximated as a black body at ~ 5800 K?
How do you justify more code being written by following clean code practices?
How many people need to be born every 8 years to sustain population?
How to preserve electronics (computers, iPads and phones) for hundreds of years
Given this phrasing in the lease, when should I pay my rent?
Animation: customize bounce interpolation
Do I have to take mana from my deck or hand when tapping a dual land?
What happens if I try to grapple mirror image?
Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?
missing yearmon labels using ggplot scale_x_yearmon
How to display the December in xaxis when using autoplot and yearmonRotating and spacing axis labels in ggplot2working with months in zooPlotting monthly data with ggplotggplot2 stats=“identity” and stacking colors in bar plot gives “striped” bar chartBarplot without lexicographical order in ggplotggplot geom_text not seating on top of barsggplot: line plot for discrete x-axisConverting a factor time variable to yearmon variableHow to reorder the groups in a grouped bar-chartsort by month and year R
I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?
Example data:
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
df$dates <- as.yearmon(df$dates)
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_yearmon(format="%Y %m")
r ggplot2 graph zoo
add a comment |
I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?
Example data:
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
df$dates <- as.yearmon(df$dates)
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_yearmon(format="%Y %m")
r ggplot2 graph zoo
add a comment |
I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?
Example data:
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
df$dates <- as.yearmon(df$dates)
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_yearmon(format="%Y %m")
r ggplot2 graph zoo
I have grouped some data by month and year, converted to yearmon using zoo and am now plotting it in ggplot. Does anyone know why one of the ticklabels are missing and there is one for 2018-07, when there is no data for that month?
Example data:
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6))
df$dates <- as.yearmon(df$dates)
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_yearmon(format="%Y %m")
r ggplot2 graph zoo
r ggplot2 graph zoo
asked Feb 8 at 11:38
Dom BurnsDom Burns
400415
400415
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I think scale_x_yearmon
was meant for xy plots as it calls scale_x_continuous
but we can just call scale_x_continuous
ourselves like this (only the line marked ## is changed):
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##
add a comment |
I think it's an issue with plotting zoo
objects. Use the standard Date
class and specify the date label in ggplot. You'll need to add the day into the character string for your dates
column. Then you can use scale_x_date
and specify the date_labels
.
library(tidyverse)
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
arrange(dates) %>%
mutate(dates = as.Date(paste0(dates, "-01")))
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
theme_light() +
xlab('Month') +
ylab('values')
It is not an issue with plotting zoo objects. There are no zoo objects in this problem.
– G. Grothendieck
Feb 8 at 12:16
Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output
– nycrefugee
Feb 8 at 12:27
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%2f54591625%2fmissing-yearmon-labels-using-ggplot-scale-x-yearmon%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think scale_x_yearmon
was meant for xy plots as it calls scale_x_continuous
but we can just call scale_x_continuous
ourselves like this (only the line marked ## is changed):
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##
add a comment |
I think scale_x_yearmon
was meant for xy plots as it calls scale_x_continuous
but we can just call scale_x_continuous
ourselves like this (only the line marked ## is changed):
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##
add a comment |
I think scale_x_yearmon
was meant for xy plots as it calls scale_x_continuous
but we can just call scale_x_continuous
ourselves like this (only the line marked ## is changed):
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##
I think scale_x_yearmon
was meant for xy plots as it calls scale_x_continuous
but we can just call scale_x_continuous
ourselves like this (only the line marked ## is changed):
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
theme_light() +
xlab('Month') +
ylab('values')+
scale_x_continuous(breaks=as.numeric(df$dates), labels=format(df$dates,"%Y %m")) ##
answered Feb 8 at 12:09
G. GrothendieckG. Grothendieck
153k10135243
153k10135243
add a comment |
add a comment |
I think it's an issue with plotting zoo
objects. Use the standard Date
class and specify the date label in ggplot. You'll need to add the day into the character string for your dates
column. Then you can use scale_x_date
and specify the date_labels
.
library(tidyverse)
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
arrange(dates) %>%
mutate(dates = as.Date(paste0(dates, "-01")))
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
theme_light() +
xlab('Month') +
ylab('values')
It is not an issue with plotting zoo objects. There are no zoo objects in this problem.
– G. Grothendieck
Feb 8 at 12:16
Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output
– nycrefugee
Feb 8 at 12:27
add a comment |
I think it's an issue with plotting zoo
objects. Use the standard Date
class and specify the date label in ggplot. You'll need to add the day into the character string for your dates
column. Then you can use scale_x_date
and specify the date_labels
.
library(tidyverse)
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
arrange(dates) %>%
mutate(dates = as.Date(paste0(dates, "-01")))
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
theme_light() +
xlab('Month') +
ylab('values')
It is not an issue with plotting zoo objects. There are no zoo objects in this problem.
– G. Grothendieck
Feb 8 at 12:16
Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output
– nycrefugee
Feb 8 at 12:27
add a comment |
I think it's an issue with plotting zoo
objects. Use the standard Date
class and specify the date label in ggplot. You'll need to add the day into the character string for your dates
column. Then you can use scale_x_date
and specify the date_labels
.
library(tidyverse)
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
arrange(dates) %>%
mutate(dates = as.Date(paste0(dates, "-01")))
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
theme_light() +
xlab('Month') +
ylab('values')
I think it's an issue with plotting zoo
objects. Use the standard Date
class and specify the date label in ggplot. You'll need to add the day into the character string for your dates
column. Then you can use scale_x_date
and specify the date_labels
.
library(tidyverse)
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
arrange(dates) %>%
mutate(dates = as.Date(paste0(dates, "-01")))
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
theme_light() +
xlab('Month') +
ylab('values')
answered Feb 8 at 12:01
nycrefugeenycrefugee
764418
764418
It is not an issue with plotting zoo objects. There are no zoo objects in this problem.
– G. Grothendieck
Feb 8 at 12:16
Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output
– nycrefugee
Feb 8 at 12:27
add a comment |
It is not an issue with plotting zoo objects. There are no zoo objects in this problem.
– G. Grothendieck
Feb 8 at 12:16
Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output
– nycrefugee
Feb 8 at 12:27
It is not an issue with plotting zoo objects. There are no zoo objects in this problem.
– G. Grothendieck
Feb 8 at 12:16
It is not an issue with plotting zoo objects. There are no zoo objects in this problem.
– G. Grothendieck
Feb 8 at 12:16
Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output
– nycrefugee
Feb 8 at 12:27
Sorry I meant yearmon class. I don’t know what’s causing the problem but the solution above provides the desired output
– nycrefugee
Feb 8 at 12:27
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%2f54591625%2fmissing-yearmon-labels-using-ggplot-scale-x-yearmon%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