2015-07-28 117 views
0

我的df是一个活动中个人(行)和他们花费的数量(列)的数据库。我想提请R中的散点图,具有以下特点:R scatterplot y轴分组

X轴:LOG(消费金额) y轴:登录

(那度过这一数额人数)这是多远我得到了:

plot(log(df$Amount), log(df$???)) 

我该怎么做?谢谢!

我DF看起来是这样的:

df 
    Name Surname Amount 
    John  Smith  223 
    Mary Osborne 127 
    Mark  Bloke  45 

这就是我心目中

enter image description here

+0

提供一个可再现的代码示例可能很有用。那么,如何死掉'df'的样子。 – drmariod

+0

@ drmariod编辑 – Billaus

+0

hm,所以你希望有更多的人花费223的金额?在这种情况下,'table(df $ Amount)'会返回数字。 – drmariod

回答

1

(陈(2012)从文件采取)试试这个:

library(dplyr) 
library(scales) # To let you make plotted points transparent 
# Make some toy data that matches your df's structure 
set.seed(1) 
df <- data.frame(Name = rep(letters, 4), Surname = rep(LETTERS, 4), Amount = rnorm(4 * length(LETTERS), 200, 50)) 
# Use dplyr to get counts of loans in each 5-dollar bin, then merge those counts back 
# into the original data frame to use as y values in plot to come. 
dfsum <- df %>% 
    mutate(Bins=cut(Amount, breaks=seq(round(min(Amount), -1) - 5, round(max(Amount) + 5, -1), by=5))) # Per AkhilNair's comment 
    group_by(Bins) %>% 
    tally() %>% 
    merge(df, ., all=TRUE) 
# Make the plot with the new df with the x-axis on a log scale 
with(dfsum, plot(x = log(Amount), y = n, ylab="Number around this amount", pch=20, col = alpha("black", 0.5))) 

以下是生产的产品: enter image description here