You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ggplot2 has a very elegant way of plotting graphs, especially statistical graphs. However, I have encountered some difficulties in adjusting the area graph.
I want to plot areas of two colors, red for parts greater than 0, and blue for parts less than 0. After trying a few approaches (see code below), it was possible to approximate the desired result in a large dataset, but there were still some problems.
Is there a suggestion or a better way to present this part of the code?
test = tibble(x=1:5,
y = c(-1,1,3,-4,2)) |>
mutate(y_na = ifelse(y<0, y, 0), y_po = ifelse(y>0, y, 0))
ggplot(test)+
geom_area(aes(x = x, y = y_po),fill='red')+
geom_area(aes(x = x, y = y_na),fill='blue')
The text was updated successfully, but these errors were encountered:
ggplot2 has a very elegant way of plotting graphs, especially statistical graphs. However, I have encountered some difficulties in adjusting the area graph.
I want to plot areas of two colors, red for parts greater than 0, and blue for parts less than 0. After trying a few approaches (see code below), it was possible to approximate the desired result in a large dataset, but there were still some problems.
Is there a suggestion or a better way to present this part of the code?
Some some representations of matplotlib would be more concise and predictable, so I hope there is some reference:
[matplotlib](https://matplotlib.org/stable/gallery/lines_bars_and_markers/fill_betweenx_demo.html
https://matplotlib.org/stable/gallery/lines_bars_and_markers/fill_between_demo.html (interpolate parameter))
The text was updated successfully, but these errors were encountered: