Home>

CSV file with the following structure

X, Y, freq, h, s, v
A, A, 5,60,255,125
B, A, 0,60,255,0
C, A, 1,60,255,25
D, A, 0,60,255,0
A, B, 0,120,255,0
     .
     .
     .


I read it with R Studio and tried to create a graph with ggplot, but I got an error.

>data<-read.csv ("C: \\ Users \\ Name \\ CSV \\ data.csv", header = T)
>ggplot (data, aes (x = X.axis, y = Y.axis)) +
+ geom_point (aes (size = freq), shape = 21, color = hsv (h, s, v, 0.5), fill = hsv (h, s, v, 0.5)) +
+ scale_size_area (max_size = 20, guide = FALSE) + theme (axis.text.x = element_text (angle = 90, hjust = 1))
 Error in hsv (h, s, v, 0.5): Missing object 'h'


Therefore, the part of the color specification was enclosed with aes (), but it seems that aes () does not like anything.

>ggplot (data, aes (x = X.axis, y = Y.axis)) +
+ geom_point (aes (size = freq), shape = 21, aes (colour = hsv (h, s, v, 0.5)), aes (fill = hsv (h, s, v, 0.5))) +
+ scale_size_area (max_size = 20, guide = FALSE) + theme (axis.text.x = element_text (angle = 90, hjust = 1))
 Error: `data` must be a data frame, or other object coercible by` fortify () `, not an S3 object with class uneval
Did you accidentally pass `aes ()` to the `data` argument?
Run `rlang :: last_error ()` to see where the error occurred.
>rlang :: last_error ()
<error/rlang_error>
`data` must be a data frame, or other object coercible by` fortify () `, not an S3 object with class uneval
Did you accidentally pass `aes ()` to the `data` argument?
Backtrace:
 1.ggplot2 :: geom_point (...)
 2.ggplot2 :: layer (...)
 4. ggplot2 ::: fortify.default (data)
Run `rlang :: last_trace ()` to see the full context.


By the way, if you do the following, the colors of the bubbles are all gray, but the graph will be drawn successfully.

>ggplot (child.cmp.bub, aes (x = X.axis, y = Y.axis)) +
+ geom_point (aes (size = freq), shape = 21, color = "darkgrey", fill = "grey") +
+ scale_size_area (max_size = 20, guide = FALSE) + theme (axis.text.x = element_text (angle = 90, hjust = 1))


  • Answer # 1

    ggplot (data, aes (x = X, y = Y)) +
           geom_point (aes (size = freq), shape = 21, color = hsv (data $h/255, data $s/255, data $v/255,0.5), fill = hsv (data $h/255, data $s/255, data $v/255,0.5)) +
           scale_size_area (max_size = 20, guide = FALSE) + theme (axis.text.x = element_text (angle = 90, hjust = 1))