haimen haimen - 3 months ago 9
R Question

Barplot showing abnormal values in x axis

I have a data set as follows,

data1

date_value value
(date) (dbl)
1 2016-06-22 72.30
2 2016-06-23 64.46
3 2016-06-24 49.25


I want to plot this in a bar graph and following is the code,

ggplot(aes(x = date_value, y = value), data = data1) + geom_bar(stat='identity')


but I am getting the following graph, were the X-axis is corrupted with some values. From the below picture, we can see that the x-axis is not having proper values and disturbed by others. Can anybody help me in solving what is the problem?

enter image description here

Answer

I think the problem is that your date labels are trying to be displayed as datetime values. Try this:

ggplot(aes(x = date_value, y = value), data = data1) + geom_bar(stat='identity') + scale_x_date(date_labels="%b %d")

enter image description here

Comments