Skip to content

geom_area gives odd results for data with duplicated x values #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fmitha opened this issue Apr 7, 2013 · 3 comments
Closed

geom_area gives odd results for data with duplicated x values #795

fmitha opened this issue Apr 7, 2013 · 3 comments

Comments

@fmitha
Copy link

fmitha commented Apr 7, 2013

Call this file dat.csv.

"x","y"
0.1,0.9
0.2,0.8
0.3,0.8
0.3,0.8
0.4,0.7
0.5,0.8
0.6,0.8
0.7,0.8
0.8,0.75
0.8,0.76
0.9,0.8
1.0,0.7

Then

#!/usr/bin/Rscript
library(ggplot2)
stat = read.csv("dat.csv")
png(file = "graph.png")
stat = ggplot() + geom_area(data=stat, aes(x, y))
print(stat)
dev.off()

gives a plot that is a little curious. See displayed graph. The
problem is that the x value 0.3 is duplicated. This might be
considered an error, but could be handled more
gracefully. Additionally, I would like to make a plea for points like
(0.8,0.75) and (0.8,0.76) to be dealt with in a reasonable way. Such
values can easily be produced as a result of rounding errors or
simulations that are not using enough precision. I suspect that
whatever geom_area would do with (0.8,0.75) & (0.8,0.76) is masked by
the duplicate x value problem.

Tested on Debian squeeze with R 2.15.3 and 0.9.3.1.

graph

@wch
Copy link
Member

wch commented Apr 7, 2013

Cleaned-up example:

dat <- read.csv(header=T, text='
x,y
0.1,0.9
0.2,0.8
0.3,0.8
0.3,0.8
0.4,0.7
0.5,0.8
0.6,0.8
0.7,0.8
0.8,0.75
0.8,0.76
0.9,0.8
1.0,0.7
')

library(ggplot2)

# Stacked
ggplot(dat, aes(x=x, y=y)) + geom_area()

I think the problem is being caused by position="stack". This makes it look as expected:

ggplot(dat, aes(x=x, y=y)) + geom_area(position="identity")

@fmitha
Copy link
Author

fmitha commented Apr 7, 2013

Hi Chang,

You're right. That does fix the problem. I should have looked again at the documentation for geom_area. So, I guess this is user errror. However. the document is a little sketchy. For example, for the page for geom_area, e.g. Area Plot, it is not clear what the different options for position are,
nor are there any examples given.

@fmitha
Copy link
Author

fmitha commented May 13, 2013

Shall I close this?

@hadley hadley closed this as completed Feb 24, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants