-
Notifications
You must be signed in to change notification settings - Fork 633
Size and Color inside marker not working properly in R #1351
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
Comments
I see what looks to be a dplyr error during creation of Error in .f(.x[[i]], ...) : object 'UNRATENSA' not found |
Please do try to reduce the complexity of your example |
Ow, sure, sorry that my example was not working! Here's a much simpler example of what I'm referring to. When you arrange the dataset, the markers are colored appropriately, but if you don't, plotly colors alphabetically (perhaps, it does some arrange internally... I don't know...). Am I missing something or my question is justified? ps.: I attached a zip file with the data. Please let know if you could run the example. Thank you!
|
That zip file uncompresses to a unix executable? |
Hm... I don't know what might be happening... Please try using this .csv file (I created a repo). Let me know if it works for you. Thanks, |
Ok, this is what I get, were you expecting something different? library(plotly)
f <- "https://raw.githubusercontent.com/renanxcortes/repo_for_supplementary_files/master/data_issue_1351.csv"
base_aux_states <- readr::read_csv(f) %>%
filter(Seasonal_Type == "URN", year == 2018, month == 1)
# Scatter Plot
base_aux_states %>%
plot_ly(x = ~Ace,
y = ~Var,
type = 'scatter',
mode = 'markers',
marker = list(size = ifelse(base_aux_states$ST == "US", 20, 10),
color = ifelse(base_aux_states$ST == "US", "red","#004B82")
),
hoverinfo = "text",
text = paste("", base_aux_states$ST, "<br>",
"Growth: ", round(base_aux_states$Var, 3), "<br>",
"Acelleration: ", round(base_aux_states$Ace, 3)),
showlegend = TRUE) %>%
layout(title = paste0("Example Graph")) |
Hm... oh my God... that's really strange... When I run your code I get exactly what you get... However, when I run reading from the .rds (which basically the same data, without the new X1 column generated with your code). I get this: I'm running exactly this:
I'm using plotly version 4.8.0. Is there a way for you to test your code with reading from the .rds and see if you get the same as me? |
If you can get me a link to the rds? I have a strong feeling this is not a plotly issue though |
Ok, thanks. I sent through e-mail. |
Ahh, it appears the dplyr grouping is messing something up in plotly. You can fix it for now by base_aux_states <- readRDS("data_issue_1351.rds") %>%
ungroup() %>%
filter(Seasonal_Type == "URN", year == 2018, month == 1)
# Scatter Plot
base_aux_states %>%
plot_ly(x = ~Ace,
y = ~Var,
type = 'scatter',
mode = 'markers',
marker = list(size = if_else(base_aux_states$ST == "US", 20, 10),
color = if_else(base_aux_states$ST == "US", "red", "#004B82")
),
hoverinfo = "text",
text = paste("", base_aux_states$ST, "<br>",
"Growth: ", round(base_aux_states$Var, 3), "<br>",
"Acelleration: ", round(base_aux_states$Ace, 3)),
showlegend = TRUE) %>%
layout(title = paste0("Example Graph")) I'd consider this a plotly bug though |
Oh! Sure, the data was grouped, I didn't remember that! Thank you! Hopefully you'll fix this! |
Hello, When I was running a code that was supposed to draw a scatterplot and color and resize a single dot of it, I realized that it wasn't working properly. The only way to fix this problem was to add an "arrange" function for the State Initial in the input dataset of plotly. Otherwise, this code was coloring and resizing the shape of Arkansas instead of the US.
It seems like the code was coloring and resizing it according to the alphabetical order of the states initial and not according to the 'ifelse' function inside the marker list.
Here's the code and the file "national_county.txt" is attached:
national_county.txt
The text was updated successfully, but these errors were encountered: