Skip to content
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

geom_points Issue In Plotly #153

Closed
cyruslentin opened this issue Jan 17, 2015 · 8 comments
Closed

geom_points Issue In Plotly #153

cyruslentin opened this issue Jan 17, 2015 · 8 comments

Comments

@cyruslentin
Copy link

Refer to URL https://cyruslentin.shinyapps.io/kiei-proj/

Giving below code for ggplot2 & plotly via ggplot2 both using Shiny Apps

In the above URL, please refer to IIP > FiscalYear > Mode = QuickGraph //normal ggplot graph
Code

fileData <- read.csv("xfyFileData.csv") #csv file is attached herewith
par(mfrow=c(1,1), pin=c(6,4))
xfyDataPlot <- ggplot(data=fileData, aes(x=ShortMonth, y=CurrentMonth, label=CurrentMonth,   group=FiscalYear, color=FiscalYear)) +
   geom_line(size=1.1) +
   geom_point(size=2, color="black") +
   xlab("Month") + ylab("IIP Data")

Note
This works as required. Note that in this graph "geom_points" are used.

In the above URL, please refer to IIP > FiscalYear > Mode = Interactive //(plotly graph)
Code

fileData <- read.csv("xfyFileData.csv") #csv file is attached herewith ... same as above
par(mfrow=c(1,1), pin=c(6,4))
xfyDataPlot <- ggplot(data=fileData, aes(x=ShortMonth, y=CurrentMonth, label=CurrentMonth, group=FiscalYear, color=FiscalYear)) +
   geom_line(size=1.1) +
   #geom_point(size=2, color="black") +
   xlab("Month") + ylab("IIP Data")
xfy.py <- plotly("username", "api-key", "https://plot.ly")  # Open Plotly connection
xfy.rs <- xfy.py$ggplotly(xfyDataPlot, kwargs=list(filename=paste(thisInstance,"-xfyDataPlot",sep=""), fileopt="overwrite", auto_open=F))
tags$iframe(src=xfy.rs$response$url, frameBorder="0", height=450, width=950)

Note
For plotly to generate the graph, the geom_point line has to be commented.
The error message given is "undefined columns selected"

PS - how does one attach a csv file here

@mkcor
Copy link
Contributor

mkcor commented Jan 20, 2015

This looks like a duplicate of #154 ...

You cannot directly attach a CSV file here in the GitHub issue. Please upload it somewhere (in a GitHub repo, for instance) and share the link here. Or copy-paste the top of your dataframe.

@cyruslentin
Copy link
Author

Hi Marianne Corvellec,

Thanks for your response.

As had mentioned in 154, please close 154.
Please refer to file xfyFileData.csv given at https://github.com/cyruslentin/plotly.
With this csvs file, you will be able to run both the above mentioned codes easily.

As mentioned by you, have also tried

geom_point(aes(size=2, color="black")) in the plotly code. But results not good.

Regards -- Cyrus

@cyruslentin
Copy link
Author

Sorry wrong statement given above. Used the one given below

geom_point(aes(x=ShortMonth, y=CurrentMonth, group=FiscalYear, size=2, color="black")) +

No difference was seen in the output,

BTW, if the same change is made in the ggplot code then the black dots change to pink and an extra label is seen. Wonder why?

Any help will be appreciated.

@mkcor
Copy link
Contributor

mkcor commented Jan 22, 2015

Hello,

I think the error arises because ggplotly() is trying to merge the geom_line() and the geom_point() layers into one trace. I'll investigate and get back to you.

Thanks,
Marianne

@mkcor
Copy link
Contributor

mkcor commented Jan 23, 2015

Hello @cyruslentin !

On using color (colour) as an aesthetic of geom_point, as in

geom_point(aes(x=ShortMonth, y=CurrentMonth, group=FiscalYear, size=2, color="black"))

BTW, if the same change is made in the ggplot code then the black dots change to pink and an
extra label is seen. Wonder why?

This is a pure "ggplot2" question, which is not the scope of this project, so I'll refer you to the official "ggplot2" docs http://docs.ggplot2.org/0.9.3.1/geom_point.html (see second example) and http://docs.ggplot2.org/current/aes_group_order.html (see second example also).

It does not make sense to add a category of data that you would call "black". It gets represented in pink just because that's one of the levels in the default colour scale.

@mkcor
Copy link
Contributor

mkcor commented Jan 23, 2015

Hi again @cyruslentin

I suggest using the following code:

xfyDataPlot <- ggplot(data=fileData, aes(x=ShortMonth, y=CurrentMonth,
                                         label=CurrentMonth,
                                         group=FiscalYear)) +
  geom_line(aes(color=FiscalYear), size=1.1) +
  geom_point(size=2, color="black") +
  xlab("Month") + ylab("IIP Data")

This converts well into plotly:
566

It's almost exactly like your initial version, but I have moved the color aesthetic under geom_line(), which is where it belongs/applies only. If you leave the color aesthetic under ggplot(), it carries over to the geom_point layer, just like it does to the geom_point one. But this is not what you want or what you mean, since you want all your points to be black, you don't want them to reflect distinctions in the data.

The only imperfection you get (https://plot.ly/~marianne2/566/iip-data-vs-month/) is that you are missing the legend title somehow... Will open a specific issue for this.

Thanks for reporting!

@cyruslentin
Copy link
Author

HI Marianne,

Thanks for all your efforts & also a quick revert.

Further thanks for the detailed explanation on the "color (colour) as an aesthetic of geom_point" as well as cracking the issue. Legend Title not appearing - I guess one can live with that :)

Have incorporated the same in the code and checked; this works as is discussed.

Please treat this issue as closed. Though if there is any development on Legend Title please do let me know.

Regards -- Cyrus

@mkcor
Copy link
Contributor

mkcor commented Jan 24, 2015

You're welcome, Cyrus.

Great, please refer to #159 for any update on the missing legend title issue.

@mkcor mkcor closed this as completed Jan 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants