Police found marijuana on the floor and charged everyone in the car. Can they do this?
Based on your explanation, you are not guilty of possession. However, you have put yourself in a difficult position. Your proximity to the drugs places you in an area of high suspicion. The police don't know who dropped the bag of marijuana on the floor. They also don't know how old the burnt roach in the ashtray is. It's possible they will not be able to obtain a conviction against anyone in the car because the drugs may have been left in the car prior to your friends' use.
The police or prosecutor might offer someone in the car a deal if they will inform on the party who owned the drugs. Unless someone claims the drugs as his/her own, they might try to prosecute everyone. This should not be successful though, as the burden is on them to prove beyond a reasonable doubt who put the drugs in the car and/or who exercised control over them.
Where you sat in the car and exactly where the drugs were will also be relevant. If the baggie was found between the seat and the front passenger door and you were seated shotgun, that is a stronger case against you, as your right hand would have been within inches of the bag. But if they were under the driver’s seat and you were in the right rear seat, that is much weaker. Simply being in the car where the drugs are found is not sufficient. This is a case where you should obtain a lawyer who is very experienced with drug cases and fight the charge aggressively.