This answers states that formatting tool tip (which is shown when mouse is hovered over scatter plot in plotly) can be done via text aesthetic of geom_point BUT in my another question I was told that text should not be used as aesthetic for geom_point (it is working but sometimes it causes problems please refer to my second link). So where is the truth? My goal is to create tool tips which I can format (set specific parameters as stated in first mentioned link) for geom_point.
Asked
Active
Viewed 590 times
1
Wakan Tanka
- 6,662
- 12
- 58
- 109
1 Answers
1
Place the aesthetic mapping under ggplot instead of geom_point to avoid the warning:
## This produces an "unknown aesthetic" warning
ggplot( mtcars, aes( x = wt, y = mpg ) ) + geom_point( aes( text = cyl ) )
## This doesn't
ggplot( mtcars, aes( x = wt, y = mpg, text = cyl ) ) + geom_point()
Also, consider using key aesthetic in place of text when adding simple information. The former preserves the column label.
When doing aes( ..., text = cyl ), the mouse-over label will look like this:
# wt: 2.620
# mpg: 21.0
# 6
When doing aes( ..., key = cyl ), the mouse-over label will look like this:
# wt: 2.620
# mpg: 21.0
# cyl: 6
Artem Sokolov
- 12,492
- 4
- 38
- 69