气泡图中的气泡未按精确的年月值(x轴)对齐

时间:2018-04-12 00:23:39

标签: r ggplot2

我有一个气泡图,它有一个简单的3列数据源。对于x轴我使用YYYY-MM格式,我想显示一些COUNT的总数。我期待所有气泡在x轴年月日期垂直对齐,但这不是我得到的。我想知道为什么?以及是否有理由进行这样的分配(ggplot2如何在年月日期选择那些x值而不是x值)?

代码:

System.InvalidOperationException: Unable to determine the relationship represented by navigation property 'Usuario.EnderecoResidencial' of type 'Endereco'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to determine the relationship represented by navigation property 'Usuario.EnderecoResidencial' of type 'Endereco'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

数据样本:

enter image description here

气泡图(点击放大):

enter image description here

1 个答案:

答案 0 :(得分:0)

正如@nielfws指出的那样,您正在使用geom_jitter,这实际上是geom_point(position = "jitter")的快捷方式。如果您更关心与x轴的对齐,可以使用position变量指定垂直闪避。

g <- ggplot(df, aes(x=YMDate, y=`Total Material Count`)) + 
  scale_y_log10() +
  scale_size_continuous(trans="sqrt",
                        range = c(2, 20),
                        breaks=c(1,5,10,50,100,500,1000,2000,3000)) +
  labs(subtitle="Size of Bubble= Total Material Count in MMRs",
       title="MMR Distribution - Monthly")

g <- g + geom_point(aes(col=Business, size=`Total Material Count`), alpha=0.7,
position = position_dodge(height = 1)) + 
  geom_smooth(aes(col=Business), method="lm", se=F)

您还可以在width中指定position_dodge选项。四处游来获得理想的效果。