2016-09-24 13 views
26

में एई सौंदर्य संबंधी त्रुटि के साथ उपयोग नहीं किया जाना चाहिए हाय दोस्तों मुझे बार ग्राफ की साजिश करते समय यह त्रुटि मिल रही है और मैं इसे से छुटकारा पाने में सक्षम नहीं हूं, मैंने qplot और ggplot दोनों की कोशिश की है लेकिन अभी भी एक ही त्रुटि है।आर ggplot2: stat_count() को बार ग्राफ

data_country

country conversion_rate 
    <fctr>   <dbl> 
    1 China  0.001331558 
    2 Germany  0.062428188 
    3  UK  0.052612025 
    4  US  0.037800687 

में

stat_count() must not be used with a y aesthetic 

डेटा त्रुटि बार चार्ट में और बिंदीदार चार्ट में नहीं आ रहा है:

बाद

मेरी कोड

library(dplyr) 
library(ggplot2) 

#Investigate data further to build a machine learning model 
data_country = data %>% 
      group_by(country) %>% 
      summarise(conversion_rate = mean(converted)) 
    #Ist method 
    qplot(country, conversion_rate, data = data_country,geom = "bar", stat ="identity", fill = country) 
    #2nd method 
    ggplot(data_country)+aes(x=country,y = conversion_rate)+geom_bar() 

त्रुटि है। कोई सुझाव बहुत मददगार होगा

उत्तर

52

सबसे पहले, आपका कोड थोड़ा सा है। aes()ggplot() में एक तर्क है, तो आप का उपयोग नहीं करते ggplot(...) + aes(...) + layers

दूसरा, मदद फ़ाइल ?geom_bar

By default, geom_bar uses stat="count" which makes the height of the bar proportion to the number of cases in each group (or if the weight aethetic is supplied, the sum of the weights). If you want the heights of the bars to represent values in the data, use stat="identity" and map a variable to the y aesthetic.

आप चाहते हैं दूसरे मामले में, जहां बार की ऊंचाई के बराबर है से है conversion_rate तो तुम क्या चाहते है ...

data_country <- data.frame(country = c("China", "Germany", "UK", "US"), 
      conversion_rate = c(0.001331558,0.062428188, 0.052612025, 0.037800687)) 
ggplot(data_country, aes(x=country,y = conversion_rate)) +geom_bar(stat = "identity") 

परिणाम:

enter image description here

+1

हां जिसने इसे समझाने के लिए धन्यवाद किया, मैं आपकी सहायता की सराहना करने के लिए थोड़ा नया हूं – Uasthana

संबंधित मुद्दे